Skip to content

Commit

Permalink
Improve N/A handling of temperature values
Browse files Browse the repository at this point in the history
  • Loading branch information
mletenay committed May 11, 2024
1 parent d410da1 commit 72e65ed
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 1 deletion.
2 changes: 1 addition & 1 deletion goodwe/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ def read_temp(buffer: ProtocolResponse, offset: int = None) -> float | None:
if offset is not None:
buffer.seek(offset)
value = int.from_bytes(buffer.read(2), byteorder="big", signed=True)
if value == 32767:
if value == -1 or value == 32767:
return None
else:
return float(value) / 10
Expand Down
5 changes: 5 additions & 0 deletions tests/inverter_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@
# asyncio.run(inverter.write_setting('grid_export_limit', 4000))
# print(asyncio.run(inverter.read_setting('grid_export_limit')))

# --------------------
# Get inverter modbus setting
# --------------------
# print(asyncio.run(inverter.read_setting('modbus-47000')))

# -------------------------------
# Execute modbus RTU protocol command
# -------------------------------
Expand Down
1 change: 1 addition & 0 deletions tests/sample/et/GW10K-ET_running_data_fw1023.hex
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
aa55f703fa18050b000322000000000000000000000000000000000000000000000000000000000000000000000000098c00141380000001b3098b000c1380000000f10991000813800000008400010000032cfffffff50000000000000000098a000d13800001000000d9098600061380000100000072098f00031380000100000005000000810000006c000000f700000141000001f60005016c0000014540001ee30f6f0f8300140000033400020000002000010000000000000004ac8500000000000426d50000811f0000000002bf00000005658000000001821b00000001519600010008000000000000000000000000000002000040000303580000e9feaa55f703fa18050b000322000000000000000000000000000000000000000000000000000000000000000000000000098c00141380000001b3098b000c1380000000f10991000813800000008400010000032cfffffff50000000000000000098a000d13800001000000d9098600061380000100000072098f00031380000100000005000000810000006c000000f700000141000001f60005016c0000014540001ee30f6f0f8300140000033400020000002000010000000000000004ac8500000000000426d50000811f0000000002bf00000005658000000001821b00000001519600010008000000000000000000000000000002000040000303580000e9fe
101 changes: 101 additions & 0 deletions tests/test_et.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ class GW10K_ET_fw1023_Test(EtMock):
def __init__(self, methodName='runTest'):
EtMock.__init__(self, methodName)
self.mock_response(self._READ_DEVICE_VERSION_INFO, 'GW10K-ET_device_info_fw1023.hex')
self.mock_response(self._READ_RUNNING_DATA, 'GW10K-ET_running_data_fw1023.hex')
asyncio.get_event_loop().run_until_complete(self.read_device_info())

def test_GW10K_ET_fw1023_device_info(self):
Expand All @@ -379,6 +380,106 @@ def test_GW10K_ET_setting_fw1023(self):
settings = {s.id_: s for s in self.settings()}
self.assertEqual('PeakShavingMode', type(settings.get("peak_shaving_mode")).__name__)

def test_GW10K_ET_runtime_data_fw1023(self):
# Reset sensors
self.loop.run_until_complete(self.read_device_info())
self.sensor_map = {s.id_: s.unit for s in self.sensors()}

data = self.loop.run_until_complete(self.read_runtime_data())
self.assertEqual(145, len(data))

self.assertSensor('timestamp', datetime.strptime('2024-05-11 00:03:34', '%Y-%m-%d %H:%M:%S'), '', data)
self.assertSensor('vpv1', 0.0, 'V', data)
self.assertSensor('ipv1', 0.0, 'A', data)
self.assertSensor('ppv1', 0, 'W', data)
self.assertSensor('vpv2', 0.0, 'V', data)
self.assertSensor('ipv2', 0.0, 'A', data)
self.assertSensor('ppv2', 0, 'W', data)
self.assertSensor('ppv', 0, 'W', data)
self.assertSensor('pv2_mode', 0, '', data)
self.assertSensor('pv2_mode_label', 'PV panels not connected', '', data)
self.assertSensor('pv1_mode', 0, '', data)
self.assertSensor('pv1_mode_label', 'PV panels not connected', '', data)
self.assertSensor('vgrid', 244.4, 'V', data)
self.assertSensor('igrid', 2.0, 'A', data)
self.assertSensor('fgrid', 49.92, 'Hz', data)
self.assertSensor('pgrid', 435, 'W', data)
self.assertSensor('vgrid2', 244.3, 'V', data)
self.assertSensor('igrid2', 1.2, 'A', data)
self.assertSensor('fgrid2', 49.92, 'Hz', data)
self.assertSensor('pgrid2', 241, 'W', data)
self.assertSensor('vgrid3', 244.9, 'V', data)
self.assertSensor('igrid3', 0.8, 'A', data)
self.assertSensor('fgrid3', 49.92, 'Hz', data)
self.assertSensor('pgrid3', 132, 'W', data)
self.assertSensor('grid_mode', 1, '', data)
self.assertSensor('grid_mode_label', 'Connected to grid', '', data)
self.assertSensor('total_inverter_power', 812, 'W', data)
self.assertSensor('active_power', -11, 'W', data)
self.assertSensor('grid_in_out', 0, '', data)
self.assertSensor('grid_in_out_label', 'Idle', '', data)
self.assertSensor('reactive_power', 0, 'var', data)
self.assertSensor('apparent_power', 0, 'VA', data)
self.assertSensor('backup_v1', 244.2, 'V', data)
self.assertSensor('backup_i1', 1.3, 'A', data)
self.assertSensor('backup_f1', 49.92, 'Hz', data)
self.assertSensor('load_mode1', 1, '', data)
self.assertSensor('backup_p1', 217, 'W', data)
self.assertSensor('backup_v2', 243.8, 'V', data)
self.assertSensor('backup_i2', 0.6, 'A', data)
self.assertSensor('backup_f2', 49.92, 'Hz', data)
self.assertSensor('load_mode2', 1, '', data)
self.assertSensor('backup_p2', 114, 'W', data)
self.assertSensor('backup_v3', 244.7, 'V', data)
self.assertSensor('backup_i3', 0.3, 'A', data)
self.assertSensor('backup_f3', 49.92, 'Hz', data)
self.assertSensor('load_mode3', 1, '', data)
self.assertSensor('backup_p3', 5, 'W', data)
self.assertSensor('load_p1', 129, 'W', data)
self.assertSensor('load_p2', 108, 'W', data)
self.assertSensor('load_p3', 247, 'W', data)
self.assertSensor('backup_ptotal', 321, 'W', data)
self.assertSensor('load_ptotal', 502, 'W', data)
self.assertSensor('ups_load', 5, '%', data)
self.assertSensor('temperature_air', 36.4, 'C', data)
self.assertSensor('temperature_module', 0.0, 'C', data)
self.assertSensor('temperature', 32.5, 'C', data)
self.assertSensor('function_bit', 16384, '', data)
self.assertSensor('bus_voltage', 790.7, 'V', data)
self.assertSensor('nbus_voltage', 395.1, 'V', data)
self.assertSensor('vbattery1', 397.1, 'V', data)
self.assertSensor('ibattery1', 2.0, 'A', data)
self.assertSensor('pbattery1', 820, 'W', data)
self.assertSensor('battery_mode', 2, '', data)
self.assertSensor('battery_mode_label', 'Discharge', '', data)
self.assertSensor('warning_code', 0, '', data)
self.assertSensor('safety_country', 32, '', data)
self.assertSensor('safety_country_label', '50Hz 230Vac Default', '', data)
self.assertSensor('work_mode', 1, '', data)
self.assertSensor('work_mode_label', 'Normal (On-Grid)', '', data)
self.assertSensor('operation_mode', 0, '', data)
self.assertSensor('error_codes', 0, '', data)
self.assertSensor('errors', '', '', data)
self.assertSensor('e_total', 30630.9, 'kWh', data)
self.assertSensor('e_day', None, 'kWh', data)
self.assertSensor('e_total_exp', 27208.5, 'kWh', data)
self.assertSensor('h_total', 33055, 'h', data)
self.assertSensor('e_day_exp', None, 'kWh', data)
self.assertSensor('e_total_imp', 70.3, 'kWh', data)
self.assertSensor('e_day_imp', None, 'kWh', data)
self.assertSensor('e_load_total', 35366.4, 'kWh', data)
self.assertSensor('e_load_day', None, 'kWh', data)
self.assertSensor('e_bat_charge_total', 9884.3, 'kWh', data)
self.assertSensor('e_bat_charge_day', None, 'kWh', data)
self.assertSensor('e_bat_discharge_total', 8642.2, 'kWh', data)
self.assertSensor('e_bat_discharge_day', 0.1, 'kWh', data)
self.assertSensor('diagnose_result', 33554496, '', data)
self.assertSensor('diagnose_result_label', 'Discharge Driver On, PF value set', '', data)
self.assertSensor('house_consumption', 831, 'W', data)
self.assertSensor('commode', 515, '', data)
self.assertSensor('rssi', 1029, '', data)
self.assertSensor('manufacture_code', 1543, '', data)


class GW6000_EH_Test(EtMock):

Expand Down
8 changes: 8 additions & 0 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ def test_energy4(self):
data = MockResponse("ffffffff")
self.assertIsNone(testee.read(data))

def test_temp(self):
testee = Temp("", 0, "", None)

data = MockResponse("0177")
self.assertEqual(37.5, testee.read(data))
data = MockResponse("ffff")
self.assertIsNone(testee.read(data))

def test_timestamp(self):
testee = Timestamp("", 0, "", None)

Expand Down

0 comments on commit 72e65ed

Please sign in to comment.