From 72e65ed00a054fc02b796b9418590f467d89339f Mon Sep 17 00:00:00 2001 From: mle Date: Sat, 11 May 2024 14:11:32 +0200 Subject: [PATCH] Improve N/A handling of temperature values --- goodwe/sensor.py | 2 +- tests/inverter_check.py | 5 + .../et/GW10K-ET_running_data_fw1023.hex | 1 + tests/test_et.py | 101 ++++++++++++++++++ tests/test_sensor.py | 8 ++ 5 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 tests/sample/et/GW10K-ET_running_data_fw1023.hex diff --git a/goodwe/sensor.py b/goodwe/sensor.py index 8e16032..40e0e92 100644 --- a/goodwe/sensor.py +++ b/goodwe/sensor.py @@ -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 diff --git a/tests/inverter_check.py b/tests/inverter_check.py index 9c56862..a1191f3 100644 --- a/tests/inverter_check.py +++ b/tests/inverter_check.py @@ -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 # ------------------------------- diff --git a/tests/sample/et/GW10K-ET_running_data_fw1023.hex b/tests/sample/et/GW10K-ET_running_data_fw1023.hex new file mode 100644 index 0000000..5ff204e --- /dev/null +++ b/tests/sample/et/GW10K-ET_running_data_fw1023.hex @@ -0,0 +1 @@ +aa55f703fa18050b000322000000000000000000000000000000000000000000000000000000000000000000000000098c00141380000001b3098b000c1380000000f10991000813800000008400010000032cfffffff50000000000000000098a000d13800001000000d9098600061380000100000072098f00031380000100000005000000810000006c000000f700000141000001f60005016c0000014540001ee30f6f0f8300140000033400020000002000010000000000000004ac8500000000000426d50000811f0000000002bf00000005658000000001821b00000001519600010008000000000000000000000000000002000040000303580000e9feaa55f703fa18050b000322000000000000000000000000000000000000000000000000000000000000000000000000098c00141380000001b3098b000c1380000000f10991000813800000008400010000032cfffffff50000000000000000098a000d13800001000000d9098600061380000100000072098f00031380000100000005000000810000006c000000f700000141000001f60005016c0000014540001ee30f6f0f8300140000033400020000002000010000000000000004ac8500000000000426d50000811f0000000002bf00000005658000000001821b00000001519600010008000000000000000000000000000002000040000303580000e9fe \ No newline at end of file diff --git a/tests/test_et.py b/tests/test_et.py index 0fb8b35..e688b8e 100644 --- a/tests/test_et.py +++ b/tests/test_et.py @@ -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): @@ -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): diff --git a/tests/test_sensor.py b/tests/test_sensor.py index a9ee23d..c34d077 100644 --- a/tests/test_sensor.py +++ b/tests/test_sensor.py @@ -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)