Skip to content

Commit

Permalink
Add support for X1 Boost (FW Version 3) (continued) (#160)
Browse files Browse the repository at this point in the history
* Add support for X1 Boost (FW Version 3)

* Update x1_boost.py: relax the requirements on the type field to support v3

* fix order of imports

* support x1_boost_g4

* linting

* add entrypoint

* linting

* Remove inverter temperature as it is not exposed in the x1_boost_g4_v3

---------

Co-authored-by: martijnvdmolen <[email protected]>
Co-authored-by: Richard Nauber <[email protected]>
  • Loading branch information
3 people authored Sep 13, 2024
1 parent aced347 commit 9f5c7cf
Show file tree
Hide file tree
Showing 7 changed files with 354 additions and 3 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"qvolt_hyb_g3_3p = solax.inverters.qvolt_hyb_g3_3p:QVOLTHYBG33P",
"x1 = solax.inverters.x1:X1",
"x1_boost = solax.inverters.x1_boost:X1Boost",
"x1_boost_g4 = solax.inverters.x1_boost_g4:X1BoostG4",
"x1_hybrid_gen4 = solax.inverters.x1_hybrid_gen4:X1HybridGen4",
"x1_mini = solax.inverters.x1_mini:X1Mini",
"x1_mini_v34 = solax.inverters.x1_mini_v34:X1MiniV34",
Expand Down
2 changes: 2 additions & 0 deletions solax/inverters/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .qvolt_hyb_g3_3p import QVOLTHYBG33P
from .x1 import X1
from .x1_boost import X1Boost
from .x1_boost_g4 import X1BoostG4
from .x1_hybrid_gen4 import X1HybridGen4
from .x1_mini import X1Mini
from .x1_mini_v34 import X1MiniV34
Expand All @@ -24,6 +25,7 @@
"X3HybridG4",
"X3",
"X1Boost",
"X1BoostG4",
"X1HybridGen4",
"X3MicProG2",
"X3Ultra",
Expand Down
5 changes: 4 additions & 1 deletion solax/inverters/x1_boost.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ class X1Boost(Inverter):
vol.Required("data"): vol.Schema(
vol.All(
[vol.Coerce(float)],
vol.Length(min=200, max=200),
vol.Any(
vol.Length(min=100, max=100),
vol.Length(min=200, max=200),
),
)
),
vol.Required("information"): vol.Schema(
Expand Down
68 changes: 68 additions & 0 deletions solax/inverters/x1_boost_g4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from typing import Any, Dict, Optional

import voluptuous as vol

from solax.inverter import Inverter
from solax.units import DailyTotal, Total, Units
from solax.utils import div10, div100, pack_u16, to_signed


class X1BoostG4(Inverter):
"""
X1-Boost gen 4 with Pocket WiFi 3.009.03
Includes X-Forwarded-For for direct LAN API access
"""

# pylint: disable=duplicate-code
_schema = vol.Schema(
{
vol.Required("type", "type"): vol.All(int, 18),
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 response_decoder(cls):
return {
"AC Voltage": (0, Units.V, div10),
"AC Output Current": (1, Units.A, div10),
"AC Output Power": (3, Units.W),
"PV1 Voltage": (4, Units.V, div10),
"PV2 Voltage": (5, Units.V, div10),
"PV1 Current": (8, Units.A, div10),
"PV2 Current": (9, Units.A, div10),
"PV1 Power": (13, Units.W),
"PV2 Power": (14, Units.W),
"AC Frequency": (2, Units.HZ, div100),
"Total Generated Energy": (pack_u16(19, 20), Total(Units.KWH), div10),
"Today's Generated Energy": (21, DailyTotal(Units.KWH), div10),
"Exported Power": (pack_u16(72, 73), Units.W, to_signed),
"Total Export Energy": (pack_u16(74, 75), Total(Units.KWH), div100),
"Total Import Energy": (pack_u16(76, 77), Total(Units.KWH), div100),
}

@classmethod
def inverter_serial_number_getter(cls, response: Dict[str, Any]) -> Optional[str]:
return response["information"][2]

@classmethod
def build_all_variants(cls, host, port, pwd=""):
versions = [
cls._build(host, port, pwd, True),
cls._build(host, port, pwd, False),
]
for inverter in versions:
inverter.http_client = inverter.http_client.with_headers(
{"X-Forwarded-For": "5.8.8.8"}
)
return versions
24 changes: 24 additions & 0 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
from tests.samples.expected_values import (
QVOLTHYBG33P_VALUES,
X1_BOOST_VALUES,
X1_BOOST_VALUES_G4_V3,
X1_BOOST_VALUES_OVERFLOWN,
X1_BOOST_VALUES_V3,
X1_HYBRID_G4_VALUES,
X1_MINI_VALUES,
X1_MINI_VALUES_V34,
Expand All @@ -29,7 +31,9 @@
QVOLTHYBG33P_RESPONSE_V34,
X1_BOOST_AIR_MINI_RESPONSE,
X1_BOOST_RESPONSE,
X1_BOOST_RESPONSE_G4_V3,
X1_BOOST_RESPONSE_OVERFLOWN,
X1_BOOST_RESPONSE_V3,
X1_HYBRID_G3_2X_MPPT_RESPONSE,
X1_HYBRID_G3_RESPONSE,
X1_HYBRID_G4_RESPONSE,
Expand Down Expand Up @@ -137,6 +141,26 @@ def simple_http_fixture(httpserver):
headers=X_FORWARDED_HEADER,
data=None,
),
InverterUnderTest(
uri="/",
method="POST",
query_string="optType=ReadRealTimeData",
response=X1_BOOST_RESPONSE_V3,
inverter=inverter.X1Boost,
values=X1_BOOST_VALUES_V3,
headers=X_FORWARDED_HEADER,
data=None,
),
InverterUnderTest(
uri="/",
method="POST",
query_string="optType=ReadRealTimeData",
response=X1_BOOST_RESPONSE_G4_V3,
inverter=inverter.X1BoostG4,
values=X1_BOOST_VALUES_G4_V3,
headers=X_FORWARDED_HEADER,
data=None,
),
InverterUnderTest(
uri="/",
method="POST",
Expand Down
39 changes: 37 additions & 2 deletions tests/samples/expected_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"Grid Imported Energy": 42,
}


X3_VALUES = {
"PV1 Current": 0,
"PV2 Current": 1,
Expand Down Expand Up @@ -410,7 +409,6 @@
"Inverter Temperature": 41,
}


X1_MINI_VALUES_V34_VER3 = {
"Network Voltage": 234.8,
"Output Current": 0.7,
Expand Down Expand Up @@ -468,6 +466,25 @@
"Total Import Energy": 81.84,
}

X1_BOOST_VALUES_V3 = {
"AC Voltage": 228.1,
"AC Output Current": 3.1,
"AC Output Power": 703.0,
"PV1 Voltage": 120.7,
"PV2 Voltage": 125.4,
"PV1 Current": 2.9,
"PV2 Current": 2.9,
"PV1 Power": 356.0,
"PV2 Power": 365.0,
"AC Frequency": 50.02,
"Total Generated Energy": 2029.3,
"Today's Generated Energy": 5.0,
"Inverter Temperature": 30.0,
"Exported Power": 0.0,
"Total Export Energy": 0.0,
"Total Import Energy": 0.0,
}

X1_BOOST_VALUES_OVERFLOWN = {
"AC Voltage": 237.4,
"AC Output Current": 6.7,
Expand All @@ -487,6 +504,24 @@
"Total Import Energy": 1850.05,
}

X1_BOOST_VALUES_G4_V3 = {
"AC Voltage": 239.7,
"AC Output Current": 0.9,
"AC Output Power": 128.0,
"PV1 Voltage": 164.5,
"PV2 Voltage": 0.0,
"PV1 Current": 0.8,
"PV2 Current": 0.0,
"PV1 Power": 138.0,
"PV2 Power": 0.0,
"AC Frequency": 50.02,
"Total Generated Energy": 7.8,
"Today's Generated Energy": 6.8,
"Exported Power": 0.0,
"Total Export Energy": 0.0,
"Total Import Energy": 0.0,
}

QVOLTHYBG33P_VALUES = {
"Network Voltage Phase 1": 221.4,
"Network Voltage Phase 2": 223.8,
Expand Down
Loading

0 comments on commit 9f5c7cf

Please sign in to comment.