diff --git a/solax/discovery.py b/solax/discovery.py index ff5b5ed..9cfdd60 100644 --- a/solax/discovery.py +++ b/solax/discovery.py @@ -14,6 +14,7 @@ X1MiniV34, X1Smart, X3HybridG4, + X3MicProG2, XHybrid, ) @@ -30,6 +31,7 @@ QVOLTHYBG33P, X1Boost, X1HybridGen4, + X3MicProG2, ] diff --git a/solax/inverters/__init__.py b/solax/inverters/__init__.py index 4fd3d70..883e9d3 100644 --- a/solax/inverters/__init__.py +++ b/solax/inverters/__init__.py @@ -7,6 +7,7 @@ from .x1_smart import X1Smart from .x3 import X3 from .x3_hybrid_g4 import X3HybridG4 +from .x3_mic_pro_g2 import X3MicProG2 from .x3_v34 import X3V34 from .x_hybrid import XHybrid @@ -22,4 +23,5 @@ "X3", "X1Boost", "X1HybridGen4", + "X3MicProG2", ] diff --git a/solax/inverters/x3_mic_pro_g2.py b/solax/inverters/x3_mic_pro_g2.py new file mode 100644 index 0000000..76df85f --- /dev/null +++ b/solax/inverters/x3_mic_pro_g2.py @@ -0,0 +1,78 @@ +import voluptuous as vol + +from solax.inverter import Inverter +from solax.units import Total, Units +from solax.utils import div10, div100, pack_u16, to_signed, to_signed32, twoway_div10 + + +class X3MicProG2(Inverter): + """X3MicProG2 v3.008.10""" + + # pylint: disable=duplicate-code + _schema = vol.Schema( + { + vol.Required("type"): vol.All(int, 16), + vol.Required("sn"): str, + vol.Required("ver"): str, + vol.Required("Data"): vol.Schema( + vol.All( + [vol.Coerce(float)], + vol.Length(min=100, max=100), + ) + ), + vol.Required("Information"): vol.Schema( + vol.All(vol.Length(min=10, max=10)) + ), + }, + extra=vol.REMOVE_EXTRA, + ) + + @classmethod + def build_all_variants(cls, host, port, pwd=""): + return [cls._build(host, port, pwd, False)] + + @classmethod + def _decode_run_mode(cls, run_mode): + return { + 0: "Wait", + 1: "Check", + 2: "Normal", + 3: "Fault", + 4: "Permanent Fault", + 5: "Update", + }.get(run_mode) + + @classmethod + def response_decoder(cls): + return { + "Grid 1 Voltage": (0, Units.V, div10), + "Grid 2 Voltage": (1, Units.V, div10), + "Grid 3 Voltage": (2, Units.V, div10), + "Grid 1 Current": (3, Units.A, twoway_div10), + "Grid 2 Current": (4, Units.A, twoway_div10), + "Grid 3 Current": (5, Units.A, twoway_div10), + "Grid 1 Power": (6, Units.W, to_signed), + "Grid 2 Power": (7, Units.W, to_signed), + "Grid 3 Power": (8, Units.W, to_signed), + "PV1 Voltage": (9, Units.V, div10), + "PV2 Voltage": (10, Units.V, div10), + "PV3 Voltage": (11, Units.V, div10), + "PV1 Current": (12, Units.A, div10), + "PV2 Current": (13, Units.A, div10), + "PV3 Current": (14, Units.A, div10), + "PV1 Power": (15, Units.W), + "PV2 Power": (16, Units.W), + "PV3 Power": (17, Units.W), + "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": (21, Units.NONE, X3MicProG2._decode_run_mode), + "Total Yield": (pack_u16(22, 23), Total(Units.KWH), div10), + "Daily Yield": (24, Units.KWH, div10), + "Feed-in Power ": (pack_u16(72, 73), Units.W, to_signed32), + "Total Feed-in Energy": (pack_u16(74, 75), Total(Units.KWH), div100), + "Total Consumption": (pack_u16(76, 77), Total(Units.KWH), div100), + } + + # pylint: enable=duplicate-code diff --git a/tests/fixtures.py b/tests/fixtures.py index d425616..4868ff7 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -13,6 +13,7 @@ X1_VALUES, X3_HYBRID_G4_VALUES, X3_HYBRID_VALUES, + X3_MICPRO_G2_VALUES, X3_VALUES, X3V34_HYBRID_VALUES, X3V34_HYBRID_VALUES_EPS_MODE, @@ -35,6 +36,7 @@ X3_HYBRID_G3_RESPONSE, X3_HYBRID_G4_RESPONSE, X3_MIC_RESPONSE, + X3_MICPRO_G2_RESPONSE, XHYBRID_DE01_RESPONSE, XHYBRID_DE02_RESPONSE, ) @@ -216,6 +218,16 @@ def simple_http_fixture(httpserver): headers=None, data="optType=ReadRealTimeData", ), + InverterUnderTest( + uri="/", + method="POST", + query_string=None, + response=X3_MICPRO_G2_RESPONSE, + inverter=inverter.X3MicProG2, + values=X3_MICPRO_G2_VALUES, + headers=None, + data="optType=ReadRealTimeData", + ), InverterUnderTest( uri="/", method="POST", diff --git a/tests/samples/expected_values.py b/tests/samples/expected_values.py index ed5707b..e4bf457 100644 --- a/tests/samples/expected_values.py +++ b/tests/samples/expected_values.py @@ -266,6 +266,36 @@ "Battery Voltage": 234.6, } +X3_MICPRO_G2_VALUES = { + "Grid 1 Voltage": 237.1, + "Grid 2 Voltage": 234.5, + "Grid 3 Voltage": 237.8, + "Grid 1 Current": 4.1, + "Grid 2 Current": 4.1, + "Grid 3 Current": 4.1, + "Grid 1 Power": 1018.0, + "Grid 2 Power": 992.0, + "Grid 3 Power": 970.0, + "PV1 Voltage": 174.1, + "PV2 Voltage": 174.5, + "PV3 Voltage": 0.0, + "PV1 Current": 8.8, + "PV2 Current": 8.7, + "PV3 Current": 0.0, + "PV1 Power": 1544.0, + "PV2 Power": 1531.0, + "PV3 Power": 0.0, + "Grid 1 Frequency": 49.98, + "Grid 2 Frequency": 49.99, + "Grid 3 Frequency": 49.94, + "Run Mode": "Normal", + "Total Yield": 795.7, + "Daily Yield": 20.0, + "Feed-in Power ": 2707.0, + "Total Feed-in Energy": 657.24, + "Total Consumption": 307.33, +} + X1_VALUES = { "PV1 Current": 0, "PV2 Current": 1, diff --git a/tests/samples/responses.py b/tests/samples/responses.py index 5fa9997..ad65b18 100644 --- a/tests/samples/responses.py +++ b/tests/samples/responses.py @@ -1215,7 +1215,6 @@ }, } - X1_HYBRID_G4_RESPONSE = { "type": 15, "sn": "SXxxxxxxxx", @@ -1547,7 +1546,6 @@ "Information": [0.000, 5, "X3-Hybiyd-G3", "XXXXXXX", 1, 3.00, 0.00, 3.17, 1.01], } - X3_HYBRID_G3_2X_MPPT_RESPONSE = { "type": "X3-Hybiyd-G3", "SN": "XXXXXXXXXX", @@ -2606,6 +2604,115 @@ "Information": [10.000, 14, "H34A**********", 8, 1.23, 0.00, 1.24, 1.09, 0.00, 1], } +X3_MICPRO_G2_RESPONSE = { + "sn": "SRE*******", + "ver": "3.008.10", + "type": 16, + "Data": [ + 2371, + 2345, + 2378, + 41, + 41, + 41, + 1018, + 992, + 970, + 1741, + 1745, + 0, + 88, + 87, + 0, + 1544, + 1531, + 0, + 4998, + 4999, + 4994, + 2, + 7957, + 0, + 200, + 4000, + 57, + 43, + 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, + 2707, + 0, + 188, + 1, + 30733, + 0, + 2982, + 0, + 1, + 4, + 1, + 0, + 13468, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + ], + "Information": [4.000, 16, "MC20**********", 8, 1.20, 0.00, 1.18, 1.00, 0.00, 1], +} + QVOLTHYBG33P_RESPONSE_V34 = { "sn": "SWX***", "ver": "2.034.06",