Skip to content

Commit

Permalink
X1Mini fix #36 (#41)
Browse files Browse the repository at this point in the history
Co-authored-by: Bo Biene <[email protected]>
  • Loading branch information
squishykid and BoBiene committed Aug 17, 2021
1 parent a3ff43c commit 5b58e37
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 1 deletion.
68 changes: 67 additions & 1 deletion solax/inverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
45 changes: 45 additions & 0 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 5b58e37

Please sign in to comment.