Skip to content

Commit

Permalink
feat: Add support for X3 Ultra
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Luehr committed Apr 9, 2024
1 parent 459cf1e commit b4b50ea
Show file tree
Hide file tree
Showing 4 changed files with 394 additions and 24 deletions.
42 changes: 18 additions & 24 deletions solax/inverters/x3_ultra.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,6 @@ def _decode_run_mode(cls, run_mode):
10: "Standby",
}.get(run_mode)

@classmethod
def _decode_battery_mode(cls, battery_mode):
return {
0: "Self Use Mode",
1: "Force Time Use",
2: "Back Up Mode",
3: "Feed-in Priority",
}.get(battery_mode)

@classmethod
def response_decoder(cls):
return {
Expand All @@ -88,7 +79,7 @@ def response_decoder(cls):
"Grid 1 Frequency": (16, Units.HZ, div100),
"Grid 2 Frequency": (17, Units.HZ, div100),
"Grid 3 Frequency": (18, Units.HZ, div100),
"Run mode": (19, Units.NONE),
#"Run mode": (19, Units.NONE),
"Run mode text": (19, Units.NONE, X3Ultra._decode_run_mode),
"EPS 1 Voltage": (23, Units.V, div10),
"EPS 2 Voltage": (24, Units.V, div10),
Expand All @@ -100,13 +91,19 @@ def response_decoder(cls):
"EPS 2 Power": (30, Units.W, to_signed),
"EPS 3 Power": (31, Units.W, to_signed),
"Grid Power ": (pack_u16(34, 35), Units.W, to_signed32),
# 'Battery Voltage' is twice in the json response and covered with 169, 170 below.
# "Battery Voltage": (39, Units.V, div100),
"Battery Current": (40, Units.A, twoway_div100),
"Battery Power": (41, Units.W, to_signed),
"Battery 1 Voltage": (39, Units.V, div10),
"Battery 2 Voltage": (132, Units.V, div10),
"Battery 1 Current": (40, Units.A, twoway_div100),
"Battery 2 Current": (133, Units.A, twoway_div100),
"Battery 1 Power": (41, Units.W, to_signed),
"Battery 2 Power": (134, Units.W, to_signed),
"Battery 1 Remaining Capacity": (103, Units.PERCENT),
"Battery 2 Remaining Capacity": (140, Units.PERCENT),
"Battery 1 Temperature": (105, Units.C, to_signed),
"Battery 2 Temperature": (142, Units.C, to_signed),
"Load/Generator Power": (47, Units.W, to_signed),
"Radiator Temperature": (54, Units.C, to_signed),
"Yield total": (pack_u16(68, 69), Total(Units.KWH), div10),
"Yield total": (pack_u16(58, 59), Total(Units.KWH), div10),
"Yield today": (70, Units.KWH, div10),
"Battery Discharge Energy total": (
pack_u16(74, 75),
Expand All @@ -119,16 +116,13 @@ def response_decoder(cls):
"PV Energy total": (pack_u16(80, 81), Total(Units.KWH), div10),
"EPS Energy total": (pack_u16(83, 84), Total(Units.KWH), div10),
"EPS Energy today": (85, Units.KWH, div10),
"Feed-in Energy": (pack_u16(86, 87), Total(Units.KWH), div100),
"Consumed Energy": (pack_u16(88, 89), Total(Units.KWH), div100),
"Feed-in Energy total": (pack_u16(90, 91), Total(Units.KWH), div100),
"Consumed Energy total": (pack_u16(92, 93), Total(Units.KWH), div100),
"Battery Remaining Capacity": (103, Units.PERCENT),
"Battery Temperature": (105, Units.C, to_signed),
"Feed-in Energy total": (pack_u16(86, 87), Total(Units.KWH), div100),
"Grid Consumed Energy total": (pack_u16(88, 89), Total(Units.KWH), div100),
"Feed-in Energy today": (pack_u16(90, 91), Total(Units.KWH), div100),
"Grid Consumed Energy today": (pack_u16(92, 93), Total(Units.KWH), div100),
"Battery Remaining Capacity": (158, Units.PERCENT),
"Battery Remaining Energy": (106, Units.KWH, div10),
"Battery mode": (168, Units.NONE),
"Battery mode text": (168, Units.NONE, X3Ultra._decode_battery_mode),
"Battery Voltage": (pack_u16(169, 170), Units.V, div100),
"Inverter Power": (159, Units.W, div10),
}

# 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 @@ -16,6 +16,7 @@
X3_HYBRID_G4_VALUES,
X3_HYBRID_VALUES,
X3_MICPRO_G2_VALUES,
X3_ULTRA_VALUES,
X3_VALUES,
X3V34_HYBRID_VALUES,
X3V34_HYBRID_VALUES_EPS_MODE,
Expand All @@ -41,6 +42,7 @@
X3_HYBRID_G4_RESPONSE,
X3_MIC_RESPONSE,
X3_MICPRO_G2_RESPONSE,
X3_ULTRA_RESPONSE,
XHYBRID_DE01_RESPONSE,
XHYBRID_DE02_RESPONSE,
)
Expand Down Expand Up @@ -242,6 +244,16 @@ def simple_http_fixture(httpserver):
headers=None,
data="optType=ReadRealTimeData",
),
InverterUnderTest(
uri="/",
method="POST",
query_string=None,
response=X3_ULTRA_RESPONSE,
inverter=inverter.X3Ultra,
values=X3_ULTRA_VALUES,
headers=None,
data="optType=ReadRealTimeData",
),
InverterUnderTest(
uri="/",
method="POST",
Expand Down
56 changes: 56 additions & 0 deletions tests/samples/expected_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,3 +521,59 @@
"Total feed-in energy": 286.7,
"Total consumption": 6.2,
}

X3_ULTRA_VALUES = {
"Grid 1 Voltage": 238.3,
"Grid 2 Voltage": 239.7,
"Grid 3 Voltage": 237.7,
"Grid 1 Current": 1.0,
"Grid 2 Current": 1.1,
"Grid 3 Current": 1.1,
"Grid 1 Power": 33.0,
"Grid 2 Power": 81.0,
"Grid 3 Power": 76.0,
"PV1 Voltage": 248.3,
"PV2 Voltage": 230.5,
"PV1 Current": 0.1,
"PV2 Current": 0.2,
"PV1 Power": 45.0,
"PV2 Power": 58.0,
"Grid 1 Frequency": 50.01,
"Grid 2 Frequency": 50.01,
"Grid 3 Frequency": 50.01,
"Run mode": 2.0,
"Run mode text": "Normal",
"EPS 1 Voltage": 0.0,
"EPS 2 Voltage": 0.0,
"EPS 3 Voltage": 0.0,
"EPS 1 Current": 0.0,
"EPS 2 Current": 0.0,
"EPS 3 Current": 0.0,
"EPS 1 Power": 0.0,
"EPS 2 Power": 0.0,
"EPS 3 Power": 0.0,
"Grid Power ": -152.0,
"Battery Current": 0.0,
"Battery Power": 0.0,
"Load/Generator Power": 342.0,
"Radiator Temperature": 23.0,
"Yield total": 4.4,
"Yield today": 0.1,
"Battery Discharge Energy total": 2.4,
"Battery Charge Energy total": 1.0,
"Battery Discharge Energy today": 0.0,
"Battery Charge Energy today": 0.0,
"PV Energy total": 3.4,
"EPS Energy total": 0.0,
"EPS Energy today": 0.0,
"Feed-in Energy": 0.0,
"Consumed Energy": 20.09,
"Feed-in Energy total": 0.0,
"Consumed Energy total": 2.09,
"Battery Remaining Capacity": 30.0,
"Battery Temperature": 22.0,
"Battery Remaining Energy": 3.3,
"Battery mode": 0.0,
"Battery mode text": "Self Use Mode",
"Battery Voltage": 234.6,
}
Loading

0 comments on commit b4b50ea

Please sign in to comment.