Skip to content

Commit

Permalink
Add support for X3 MIC/PRO G2 (squishykid#116)
Browse files Browse the repository at this point in the history
* Fix deprecation warning

* Add support for X3 MIC/PRO G2

* Fix sensor enumeration

* Revert "Fix sensor enumeration"

This reverts commit 05f219d.

* Revert fix for async_timeout deprecation warning

* Return inverter run mode once (as text) instead of twice (as text and numerical value)
  • Loading branch information
niclasku authored Jun 10, 2023
1 parent 9bc8d3d commit e17c930
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 2 deletions.
2 changes: 2 additions & 0 deletions solax/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
X1MiniV34,
X1Smart,
X3HybridG4,
X3MicProG2,
XHybrid,
)

Expand All @@ -30,6 +31,7 @@
QVOLTHYBG33P,
X1Boost,
X1HybridGen4,
X3MicProG2,
]


Expand Down
2 changes: 2 additions & 0 deletions solax/inverters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -22,4 +23,5 @@
"X3",
"X1Boost",
"X1HybridGen4",
"X3MicProG2",
]
78 changes: 78 additions & 0 deletions solax/inverters/x3_mic_pro_g2.py
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
)
Expand Down Expand Up @@ -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",
Expand Down
30 changes: 30 additions & 0 deletions tests/samples/expected_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
111 changes: 109 additions & 2 deletions tests/samples/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,6 @@
},
}


X1_HYBRID_G4_RESPONSE = {
"type": 15,
"sn": "SXxxxxxxxx",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit e17c930

Please sign in to comment.