Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally define unique sensor id in inverter response decoder #122

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion solax/inverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ def sensor_map(cls) -> Dict[str, Tuple[int, Measurement]]:
for name, mapping in cls.response_decoder().items():
unit = Measurement(Units.NONE)

(idx, unit_or_measurement, *_) = mapping
if isinstance(mapping, dict):
idx = mapping["unique_id"]
unit_or_measurement = mapping["decoder"][1]
else:
(idx, unit_or_measurement, *_) = mapping

if isinstance(unit_or_measurement, Units):
unit = Measurement(unit_or_measurement)
Expand Down
8 changes: 8 additions & 0 deletions solax/inverters/qvolt_hyb_g3_3p.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ def response_decoder(cls):
"Grid Frequency Phase 2": (17, Units.HZ, div100),
"Grid Frequency Phase 3": (18, Units.HZ, div100),
"Inverter Operation mode": (19, Units.NONE, cls.Processors.inverter_modes),
"Inverter Operation mode raw": {
"decoder": (19, Units.NONE),
"unique_id": 500,
},
# 20 - 32: always 0
# 33: always 1
# instead of to_signed this is actually 34 - 35,
Expand Down Expand Up @@ -156,6 +160,10 @@ def response_decoder(cls):
# 127,128 resetting counter /1000, around battery charge + discharge
# 164,165,166 some curves
"Battery Operation mode": (168, Units.NONE, cls.Processors.battery_modes),
"Battery Operation mode raw": {
"decoder": (168, Units.NONE),
"unique_id": 501,
}
# 169: div100 same as [39]
# 170-199: always 0
}
Expand Down
5 changes: 4 additions & 1 deletion solax/inverters/x3_hybrid_g4.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ def response_decoder(cls):
"Grid 2 Frequency": (17, Units.HZ, div100),
"Grid 3 Frequency": (18, Units.HZ, div100),
"Run mode": (19, Units.NONE),
"Run mode text": (19, Units.NONE, X3HybridG4._decode_run_mode),
"Run mode text": {
"decoder": (19, Units.NONE, X3HybridG4._decode_run_mode),
"unique_id": 500,
},
"EPS 1 Voltage": (23, Units.W, div10),
"EPS 2 Voltage": (24, Units.W, div10),
"EPS 3 Voltage": (25, Units.W, div10),
Expand Down
5 changes: 4 additions & 1 deletion solax/inverters/x3_mic_pro_g2.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ def response_decoder(cls):
"Grid 1 Frequency": (18, Units.HZ, div100),
"Grid 2 Frequency": (19, Units.HZ, div100),
"Grid 3 Frequency": (20, Units.HZ, div100),
# "Run Mode": (21, Units.NONE),
"Run Mode Raw": {
"decoder": (21, Units.NONE),
"unique_id": 500,
},
"Run Mode": (21, Units.NONE, X3MicProG2._decode_run_mode),
"Total Yield": (pack_u16(22, 23), Total(Units.KWH), div10),
"Daily Yield": (24, Units.KWH, div10),
Expand Down
4 changes: 4 additions & 0 deletions solax/response_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def __init__(self, schema: vol.Schema, decoder: ResponseDecoder):
def _decode_map(self) -> Dict[str, SensorIndexSpec]:
sensors: Dict[str, SensorIndexSpec] = {}
for name, mapping in self.response_decoder.items():
if isinstance(mapping, dict):
mapping = mapping["decoder"]
sensors[name] = mapping[0]
return sensors

Expand All @@ -42,6 +44,8 @@ def _postprocess_map(self) -> Dict[str, Callable[[Any], Any]]:
"""
sensors: Dict[str, Callable[[Any], Any]] = {}
for name, mapping in self.response_decoder.items():
if isinstance(mapping, dict):
mapping = mapping["decoder"]
processor = None
(_, _, *processor) = mapping
if processor:
Expand Down
3 changes: 3 additions & 0 deletions tests/samples/expected_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@
"Grid 1 Frequency": 49.98,
"Grid 2 Frequency": 49.99,
"Grid 3 Frequency": 49.94,
"Run Mode Raw": 2.0,
"Run Mode": "Normal",
"Total Yield": 795.7,
"Daily Yield": 20.0,
Expand Down Expand Up @@ -423,6 +424,7 @@
"Grid Frequency Phase 2": 50.01,
"Grid Frequency Phase 3": 50.02,
"Inverter Operation mode": "Normal",
"Inverter Operation mode raw": 2.0,
"Exported Power": -7.0,
"Battery Voltage": 323.4,
"Battery Current": 5.0,
Expand All @@ -443,6 +445,7 @@
"Battery Temperature": 35.0,
"Battery Remaining Energy": 8.8,
"Battery Operation mode": "Self Use Mode",
"Battery Operation mode raw": 0,
}

X1_HYBRID_G4_VALUES = {
Expand Down