Skip to content

Commit

Permalink
add pi30mst as model of pi30max
Browse files Browse the repository at this point in the history
  • Loading branch information
jblance authored Jan 15, 2025
1 parent 505d298 commit 8242c57
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 8 deletions.
10 changes: 7 additions & 3 deletions powermon/protocols/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@ class Protocol(StrEnum):
PI18 = auto() # WIP
PI30 = auto()
PI30MAX = auto()
PI30MST = auto()
DALY = auto()
NEEY = auto()
HELTEC = auto()
VED = auto()
JKSERIAL = auto()


def get_protocol_definition(protocol):
def get_protocol_definition(protocol, model=None):
"""
Get the protocol based on the protocol name
Get the protocol based on the protocol name and optionally model number
"""

log.debug("Protocol: %s", protocol)
Expand All @@ -50,7 +51,10 @@ def get_protocol_definition(protocol):
return PI30()
case Protocol.PI30MAX:
from powermon.protocols.pi30max import PI30MAX
return PI30MAX()
return PI30MAX(model=model)
case Protocol.PI30MST:
from powermon.protocols.pi30max import PI30MAX
return PI30MAX(model='PIP4048MST')
case Protocol.VED:
from powermon.protocols.ved import VictronEnergyDirect
return VictronEnergyDirect()
Expand Down
67 changes: 62 additions & 5 deletions powermon/protocols/pi30max.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from powermon.commands.result import ResultType
from powermon.protocols.pi30 import PI30
# from powermon.libs.errors import PowermonProtocolError
from powermon.commands.reading_definition import ResponseType
from powermon.commands.reading_definition import ReadingType

Expand Down Expand Up @@ -147,7 +148,7 @@
"reading_type": ReadingType.MESSAGE,
"response_type": ResponseType.OPTION, "options": {"00": "Grid tie", "01": "Off Grid", "10": "Hybrid"}},
{"description": "Topology", "reading_type": ReadingType.MESSAGE, "response_type": ResponseType.LIST, "options": ["transformerless", "transformer"]},
{"description": "Output Mode", "reading_type": ReadingType.MESSAGE, "response_type": ResponseType.LIST, "options": OUTPUT_MODE_LIST},
{"description": "Output Mode", "reading_type": ReadingType.MESSAGE, "device_class": "enum", "response_type": ResponseType.LIST, "options": OUTPUT_MODE_LIST},
{"description": "Battery Redischarge Voltage", "reading_type": ReadingType.VOLTS, "response_type": ResponseType.FLOAT},
{"description": "PV OK Condition",
"reading_type": ReadingType.MESSAGE,
Expand Down Expand Up @@ -386,7 +387,7 @@
"Is Load On",
"Is Configuration Changed"]},
{"description": "Output mode",
"reading_type": ReadingType.MESSAGE,
"reading_type": ReadingType.MESSAGE, "device_class": "enum",
"response_type": ResponseType.LIST,
"options": OUTPUT_MODE_LIST},
{"description": "Charger source priority",
Expand Down Expand Up @@ -862,22 +863,78 @@
},
}

MST_QPIGS2 = {
"name": "QPIGS2",
"description": "General Status Parameters inquiry 2",
"result_type": ResultType.ORDERED,
"reading_definitions": [
{"description": "PV2 Input Current",
"reading_type": ReadingType.CURRENT, "icon": "mdi:solar-power", "device_class": "current", "state_class": "measurement",
"response_type": ResponseType.FLOAT},
{"description": "PV2 Input Voltage",
"reading_type": ReadingType.VOLTS, "icon": "mdi:solar-power", "device_class": "voltage", "state_class": "measurement",
"response_type": ResponseType.FLOAT},
{"description": "Battery voltage from SCC 2",
"reading_type": ReadingType.VOLTS, "icon": "mdi:solar-power", "device_class": "voltage", "state_class": "measurement",
"response_type": ResponseType.FLOAT},
{"description": "PV2 Charging Power",
"reading_type": ReadingType.WATTS, "icon": "mdi:solar-power", "device_class": "power", "state_class": "measurement",
"response_type": ResponseType.INT},
{"description": "Device status", "reading_type": ReadingType.MESSAGE,},
{"description": "AC charging current",
"reading_type": ReadingType.CURRENT, "icon": "mdi:transmission-tower-export", "device_class": "current", "state_class": "measurement",
"response_type": ResponseType.FLOAT},
{"description": "AC charging power",
"reading_type": ReadingType.WATTS, "icon": "mdi:transmission-tower-export", "device_class": "power", "state_class": "measurement",
"response_type": ResponseType.INT},
{"description": "PV3 Input Current",
"reading_type": ReadingType.CURRENT, "icon": "mdi:solar-power", "device_class": "current", "state_class": "measurement",
"response_type": ResponseType.FLOAT},
{"description": "PV3 Input Voltage",
"reading_type": ReadingType.VOLTS, "icon": "mdi:solar-power", "device_class": "voltage", "state_class": "measurement",
"response_type": ResponseType.FLOAT},
{"description": "Battery voltage from SCC 3",
"reading_type": ReadingType.VOLTS, "icon": "mdi:solar-power", "device_class": "voltage", "state_class": "measurement",
"response_type": ResponseType.FLOAT},
{"description": "PV3 Charging Power",
"reading_type": ReadingType.WATTS, "icon": "mdi:solar-power", "device_class": "power", "state_class": "measurement",
"response_type": ResponseType.INT},
{"description": "PV total charging power",
"reading_type": ReadingType.WATTS, "icon": "mdi:solar-power", "device_class": "power", "state_class": "measurement",
"response_type": ResponseType.INT},
],
"test_responses": [
b"(03.1 327.3 52.3 123 1 1234 122 327.1 52.4 234 567 \x23\xc7\r",
],
}
COMMANDS_TO_REMOVE = ["QVFW2"]


class PI30MAX(PI30):
""" PI30 protocol handler for LV6048MAX and similar inverters """
def __str__(self):
return "PI30 protocol handler for LV6048MAX and similar inverters"
match self.model:
case 'PIP4048MST':
return "PI30 protocol handler for PIP4048MST and similar inverters"
case _:
return "PI30 protocol handler for LV6048MAX and similar inverters"

def __init__(self) -> None:
def __init__(self, model=None) -> None:
super().__init__()
self.protocol_id = b"PI30MAX"
self.model = model
self.add_command_definitions(QUERY_COMMANDS)
self.add_command_definitions(SETTER_COMMANDS, result_type=ResultType.ACK)
self.remove_command_definitions(COMMANDS_TO_REMOVE)
self.check_definitions_count(expected=67)
# self.id_command = "QSID"

if model:
log.info("%s got model specifier: %s", self.protocol_id, model)
if model == 'PIP4048MST':
self.replace_command_definition("QPIGS2", MST_QPIGS2)
self.check_definitions_count(expected=67)
# else:
# raise PowermonProtocolError(f"unknown model {model}")

self.STATUS_COMMANDS = ["QPIGS", "QPIGS2"]
self.SETTINGS_COMMANDS = ["QPIRI", "QFLAG"]
Expand Down

0 comments on commit 8242c57

Please sign in to comment.