Skip to content

Commit

Permalink
Add Peak Shavig limit and SoC settings
Browse files Browse the repository at this point in the history
Fix sign on Integer settings - default is unsigned.
  • Loading branch information
mletenay committed Apr 13, 2024
1 parent 59971c6 commit dee52be
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 8 deletions.
2 changes: 2 additions & 0 deletions goodwe/et.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ class ET(Inverter):

# Settings added in ARM firmware 22
__settings_arm_fw_22: Tuple[Sensor, ...] = (
Long("peak_shaving_power_limit", 47542, "Peak Shaving Power Limit"),
Integer("peak_shaving_soc", 47544, "Peak Shaving SoC"),
# EcoModeV2("eco_modeV2_5", 47571, "Eco Mode Version 2 Power Group 5"),
# EcoModeV2("eco_modeV2_6", 47577, "Eco Mode Version 2 Power Group 6"),
# EcoModeV2("eco_modeV2_7", 47583, "Eco Mode Version 2 Power Group 7"),
Expand Down
26 changes: 26 additions & 0 deletions goodwe/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,19 @@ def encode_value(self, value: Any, register_value: bytes = None) -> bytes:


class Integer(Sensor):
"""Sensor representing unsigned int value encoded in 2 bytes"""

def __init__(self, id_: str, offset: int, name: str, unit: str = "", kind: Optional[SensorKind] = None):
super().__init__(id_, offset, name, 2, unit, kind)

def read_value(self, data: ProtocolResponse):
return read_bytes2(data)

def encode_value(self, value: Any, register_value: bytes = None) -> bytes:
return int.to_bytes(int(value), length=2, byteorder="big", signed=False)


class IntegerS(Sensor):
"""Sensor representing signed int value encoded in 2 bytes"""

def __init__(self, id_: str, offset: int, name: str, unit: str = "", kind: Optional[SensorKind] = None):
Expand All @@ -315,6 +328,19 @@ def encode_value(self, value: Any, register_value: bytes = None) -> bytes:


class Long(Sensor):
"""Sensor representing unsigned int value encoded in 4 bytes"""

def __init__(self, id_: str, offset: int, name: str, unit: str = "", kind: Optional[SensorKind] = None):
super().__init__(id_, offset, name, 4, unit, kind)

def read_value(self, data: ProtocolResponse):
return read_bytes4(data)

def encode_value(self, value: Any, register_value: bytes = None) -> bytes:
return int.to_bytes(int(value), length=4, byteorder="big", signed=False)


class LongS(Sensor):
"""Sensor representing signed int value encoded in 4 bytes"""

def __init__(self, id_: str, offset: int, name: str, unit: str = "", kind: Optional[SensorKind] = None):
Expand Down
8 changes: 4 additions & 4 deletions tests/test_dt.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_GW6000_DT_runtime_data(self):
self.assertSensor('funbit', 0, '', data)
self.assertSensor('vbus', 601.2, 'V', data)
self.assertSensor('vnbus', 305.4, 'V', data)
self.assertSensor('derating_mode', -1, '', data)
self.assertSensor('derating_mode', 0, '', data)
self.assertSensor('derating_mode_label', '', '', data)

self.assertFalse(self.sensor_map, f"Some sensors were not tested {self.sensor_map}")
Expand Down Expand Up @@ -169,7 +169,7 @@ def test_GW8K_DT_runtime_data(self):
self.assertSensor('temperature', 45.3, 'C', data)
self.assertSensor('e_day', 0.0, 'kWh', data)
self.assertSensor('e_total', 0.0, 'kWh', data)
self.assertSensor('h_total', -1, 'h', data)
self.assertSensor('h_total', 0, 'h', data)
self.assertSensor('safety_country', 32, '', data)
self.assertSensor('safety_country_label', '50Hz 230Vac Default', '', data)
self.assertSensor('funbit', 512, '', data)
Expand Down Expand Up @@ -229,7 +229,7 @@ def test_GW5000D_NS_runtime_data(self):
self.assertSensor('funbit', 2400, '', data)
self.assertSensor('vbus', 291.7, 'V', data)
self.assertSensor('vnbus', 0, 'V', data)
self.assertSensor('derating_mode', -1, '', data)
self.assertSensor('derating_mode', 0, '', data)
self.assertSensor('derating_mode_label', '', '', data)

def test_get_grid_export_limit(self):
Expand Down Expand Up @@ -295,7 +295,7 @@ def test_GW5000_MS_runtime_data(self):
self.assertSensor('funbit', 2384, '', data)
self.assertSensor('vbus', 393.9, 'V', data)
self.assertSensor('vnbus', 0, 'V', data)
self.assertSensor('derating_mode', -1, '', data)
self.assertSensor('derating_mode', 0, '', data)
self.assertSensor('derating_mode_label', '', '', data)


Expand Down
8 changes: 4 additions & 4 deletions tests/test_et.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def test_GW10K_ET_fw1023_device_info(self):
self.assertEqual('02041-23-S00', self.arm_firmware)

def test_GW10K_ET_setting_fw1023(self):
self.assertEqual(44, len(self.settings()))
self.assertEqual(46, len(self.settings()))
settings = {s.id_: s for s in self.settings()}
self.assertEqual('PeakShavingMode', type(settings.get("peak_shaving_mode")).__name__)

Expand Down Expand Up @@ -449,7 +449,7 @@ def test_GW6000_EH_runtime_data(self):
self.assertSensor('safety_country_label', 'ES-A', '', data)
self.assertSensor('work_mode', 1, '', data)
self.assertSensor('work_mode_label', 'Normal (On-Grid)', '', data)
self.assertSensor('operation_mode', -1, '', data)
self.assertSensor('operation_mode', 0, '', data)
self.assertSensor('error_codes', 0, '', data)
self.assertSensor('errors', '', '', data)
self.assertSensor("e_total", 59.4, 'kWh', data)
Expand Down Expand Up @@ -550,7 +550,7 @@ def test_GEH10_1U_10_runtime_data(self):
self.assertSensor('safety_country_label', 'Australia A', '', data)
self.assertSensor('work_mode', 1, '', data)
self.assertSensor('work_mode_label', 'Normal (On-Grid)', '', data)
self.assertSensor('operation_mode', -1, '', data)
self.assertSensor('operation_mode', 0, '', data)
self.assertSensor('error_codes', 0, '', data)
self.assertSensor('errors', '', '', data)
self.assertSensor('e_total', 10225.8, 'kWh', data)
Expand Down Expand Up @@ -1085,7 +1085,7 @@ def test_GW29K9_ET_runtime_data(self):
self.assertSensor('meter_apparent_power3', -3175, 'VA', data)
self.assertSensor('meter_apparent_power_total', -5667, 'VA', data)
self.assertSensor('meter_type', 2, '', data)
self.assertSensor('meter_sw_version', -1, '', data)
self.assertSensor('meter_sw_version', 0, '', data)
self.assertSensor('meter2_active_power', 0, 'W', data)
self.assertSensor('meter2_e_total_exp', 0.0, 'kWh', data)
self.assertSensor('meter2_e_total_imp', 0.0, 'kWh', data)
Expand Down
11 changes: 11 additions & 0 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ def test_integer(self):
self.assertEqual(49, testee.read(data))
self.assertEqual("0031", testee.encode_value(49).hex())

data = MockResponse("ff9e")
self.assertEqual(65438, testee.read(data))
self.assertEqual("ff9e", testee.encode_value(65438).hex())

def test_integer_signed(self):
testee = IntegerS("", 0, "", "", None)

data = MockResponse("0031")
self.assertEqual(49, testee.read(data))
self.assertEqual("0031", testee.encode_value(49).hex())

data = MockResponse("ff9e")
self.assertEqual(-98, testee.read(data))
self.assertEqual("ff9e", testee.encode_value(-98).hex())
Expand Down

0 comments on commit dee52be

Please sign in to comment.