From 6bcb6cfb181739cb4378305c2bbcae8604785bef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niclas=20K=C3=BChnapfel?= Date: Sun, 11 Jun 2023 11:17:53 +0200 Subject: [PATCH 1/3] Add possibility to optionally define unique sensor id in inverter response decoder --- solax/inverter.py | 6 +++++- solax/inverters/x3_mic_pro_g2.py | 5 ++++- solax/response_parser.py | 2 ++ tests/samples/expected_values.py | 1 + 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/solax/inverter.py b/solax/inverter.py index df3042c..ba5d9e5 100644 --- a/solax/inverter.py +++ b/solax/inverter.py @@ -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) diff --git a/solax/inverters/x3_mic_pro_g2.py b/solax/inverters/x3_mic_pro_g2.py index 76df85f..7a42bbc 100644 --- a/solax/inverters/x3_mic_pro_g2.py +++ b/solax/inverters/x3_mic_pro_g2.py @@ -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": 200, + }, "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), diff --git a/solax/response_parser.py b/solax/response_parser.py index 5d6cd85..096fc77 100644 --- a/solax/response_parser.py +++ b/solax/response_parser.py @@ -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 diff --git a/tests/samples/expected_values.py b/tests/samples/expected_values.py index e4bf457..b116b76 100644 --- a/tests/samples/expected_values.py +++ b/tests/samples/expected_values.py @@ -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, From 05b1cbf1970ca5bba94d05cb981eb76779849035 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niclas=20K=C3=BChnapfel?= Date: Sun, 11 Jun 2023 12:47:53 +0200 Subject: [PATCH 2/3] Fix post-processing for new optional dict items in response decoder --- solax/response_parser.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/solax/response_parser.py b/solax/response_parser.py index 096fc77..c5a0ceb 100644 --- a/solax/response_parser.py +++ b/solax/response_parser.py @@ -44,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: From 3df1e923ca1f1d3148cec48b08d7e45518faa5a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niclas=20K=C3=BChnapfel?= Date: Sun, 11 Jun 2023 12:49:46 +0200 Subject: [PATCH 3/3] Fix and add operation mode items and add test cases --- solax/inverters/qvolt_hyb_g3_3p.py | 8 ++++++++ solax/inverters/x3_hybrid_g4.py | 5 ++++- solax/inverters/x3_mic_pro_g2.py | 2 +- tests/samples/expected_values.py | 2 ++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/solax/inverters/qvolt_hyb_g3_3p.py b/solax/inverters/qvolt_hyb_g3_3p.py index f686d3e..fc1ea9b 100644 --- a/solax/inverters/qvolt_hyb_g3_3p.py +++ b/solax/inverters/qvolt_hyb_g3_3p.py @@ -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, @@ -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 } diff --git a/solax/inverters/x3_hybrid_g4.py b/solax/inverters/x3_hybrid_g4.py index c8433aa..230cada 100644 --- a/solax/inverters/x3_hybrid_g4.py +++ b/solax/inverters/x3_hybrid_g4.py @@ -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), diff --git a/solax/inverters/x3_mic_pro_g2.py b/solax/inverters/x3_mic_pro_g2.py index 7a42bbc..587ef19 100644 --- a/solax/inverters/x3_mic_pro_g2.py +++ b/solax/inverters/x3_mic_pro_g2.py @@ -68,7 +68,7 @@ def response_decoder(cls): "Grid 3 Frequency": (20, Units.HZ, div100), "Run Mode Raw": { "decoder": (21, Units.NONE), - "unique_id": 200, + "unique_id": 500, }, "Run Mode": (21, Units.NONE, X3MicProG2._decode_run_mode), "Total Yield": (pack_u16(22, 23), Total(Units.KWH), div10), diff --git a/tests/samples/expected_values.py b/tests/samples/expected_values.py index b116b76..f843c6b 100644 --- a/tests/samples/expected_values.py +++ b/tests/samples/expected_values.py @@ -424,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, @@ -444,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 = {