From 5b58e370de3336b3417fcd42f7854a71ad404c95 Mon Sep 17 00:00:00 2001 From: Robin Wohlers-Reichel Date: Tue, 17 Aug 2021 13:20:13 +1000 Subject: [PATCH] X1Mini fix #36 (#41) Co-authored-by: Bo Biene <23037659+BoBiene@users.noreply.github.com> --- solax/inverter.py | 68 ++++++++++++++++++++++++++++++++++++++++++++++- tests/fixtures.py | 45 +++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 1 deletion(-) diff --git a/solax/inverter.py b/solax/inverter.py index 2d42536..ab0b446 100644 --- a/solax/inverter.py +++ b/solax/inverter.py @@ -521,5 +521,71 @@ def schema(cls): return cls.__schema +class X1MiniV34(InverterPost): + __schema = vol.Schema({ + vol.Required('type', 'type'): vol.All(int, 4), + vol.Required('sn',): str, + vol.Required('ver'): str, + vol.Required('Data'): vol.Schema( + vol.All( + [vol.Coerce(float)], + vol.Any( + vol.Length(min=69, max=69), + vol.Length(min=200, max=200), + ) + ) + ), + vol.Required('Information'): vol.Schema( + vol.Any( + vol.Length(min=9, max=9), + vol.Length(min=10, max=10) + ) + ), + }, extra=vol.REMOVE_EXTRA) + + __sensor_map = { + 'Network Voltage': (0, 'V', div10), + 'Output Current': (1, 'A', div10), + 'AC Power': (2, 'W'), + 'PV1 Voltage': (3, 'V', div10), + 'PV2 Voltage': (4, 'V', div10), + 'PV1 Current': (5, 'A', div10), + 'PV2 Current': (6, 'A', div10), + 'PV1 Power': (7, 'W'), + 'PV2 Power': (8, 'W'), + 'Grid Frequency': (9, 'Hz', div100), + 'Total Energy': (11, 'kWh', div10), + 'Today\'s Energy': (13, 'kWh', div10), + 'Total Feed-in Energy': (41, 'kWh', div10), + 'Total Consumption': (42, 'kWh', div10), + 'Power Now': (43, 'W', div10), + } + + @classmethod + def sensor_map(cls): + """ + Return sensor map + """ + sensors = {} + for name, (idx, unit, *_) in cls.__sensor_map.items(): + sensors[name] = (idx, unit) + return sensors + + @classmethod + def postprocess_map(cls): + """ + Return postprocessing map + """ + sensors = {} + for name, (_, _, *processor) in cls.__sensor_map.items(): + if processor: + sensors[name] = processor[0] + return sensors + + @classmethod + def schema(cls): + return cls.__schema + + # registry of inverters -REGISTRY = [XHybrid, X3, X3V34, X1, X1Mini] +REGISTRY = [XHybrid, X3, X3V34, X1, X1Mini, X1MiniV34] diff --git a/tests/fixtures.py b/tests/fixtures.py index 2e3fbd7..0da632f 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -46,6 +46,25 @@ 1, 3.25, 1.09, 1.10, 0.00] } +X1_MINI_RESPONSE_V34 = { + "sn": "XXXXXXXXXX", + "ver": "2.034.06", + "type": 4, + "Data": [2310, 15, 349, 609, 0, 58, 0, 359, 0, 5000, + 2, 3474, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 39, 0, 2518, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 41, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0], + "Information": [0.700, 4, "XXXXXXXXXXXXXX", + 1, 1.19, 0.00, 1.32, 0.00, 0.00, 1] +} + X3_MIC_RESPONSE = { "type": "X3-MIC", "SN": "XXXXXXX", @@ -388,6 +407,24 @@ 'Grid Frequency': 50, } +X1_MINI_VALUES_V34 = { + 'Network Voltage': 231.0, + 'Output Current': 1.5, + 'AC Power': 349, + 'PV1 Voltage': 60.9, + 'PV2 Voltage': 0, + 'PV1 Current': 5.8, + 'PV2 Current': 0, + 'PV1 Power': 359, + 'PV2 Power': 0, + 'Grid Frequency': 50.0, + 'Total Energy': 347.4, + 'Today\'s Energy': 1.2, + 'Total Feed-in Energy': 251.8, + 'Total Consumption': 0, + 'Power Now': 0, +} + @pytest.fixture() def simple_http_fixture(httpserver): @@ -429,6 +466,14 @@ def simple_http_fixture(httpserver): inverter=inverter.X1Mini, values=X1_MINI_VALUES, ), + InverterUnderTest( + uri="/", + method='POST', + query_string='optType=ReadRealTimeData', + response=X1_MINI_RESPONSE_V34, + inverter=inverter.X1MiniV34, + values=X1_MINI_VALUES_V34, + ), InverterUnderTest( uri="/", method='POST',