Skip to content

Commit

Permalink
Fix decoding 0 energy values
Browse files Browse the repository at this point in the history
  • Loading branch information
mletenay committed May 14, 2024
1 parent 366d356 commit a555e3e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions goodwe/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def __init__(self, id_: str, offset: int, name: str, kind: Optional[SensorKind])

def read_value(self, data: ProtocolResponse):
value = read_bytes2(data)
return float(value) / 10 if value else None
return float(value) / 10 if value is not None else None


class Energy4(Sensor):
Expand All @@ -194,7 +194,7 @@ def __init__(self, id_: str, offset: int, name: str, kind: Optional[SensorKind])

def read_value(self, data: ProtocolResponse):
value = read_bytes4(data)
return float(value) / 10 if value else None
return float(value) / 10 if value is not None else None


class Apparent(Sensor):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_dt.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def test_GW5000D_NS_runtime_data(self):
self.assertSensor("apparent_power", -1, "VA", data),
self.assertSensor("reactive_power", -1, "var", data),
self.assertSensor('temperature', 1.4, 'C', data)
self.assertSensor('e_day', None, 'kWh', data)
self.assertSensor('e_day', 0, 'kWh', data)
self.assertSensor('e_total', 881.7, 'kWh', data)
self.assertSensor('h_total', 955, 'h', data)
self.assertSensor('safety_country', 73, '', data)
Expand Down
40 changes: 20 additions & 20 deletions tests/test_et.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def test_GW10K_ET_runtime_data(self):
self.assertSensor('h_total', 9246, 'h', data)
self.assertSensor("e_day_exp", 9.8, 'kWh', data)
self.assertSensor("e_total_imp", 58.0, 'kWh', data)
self.assertSensor("e_day_imp", None, 'kWh', data)
self.assertSensor("e_day_imp", 0, 'kWh', data)
self.assertSensor("e_load_total", 8820.2, 'kWh', data)
self.assertSensor("e_load_day", 11.6, 'kWh', data)
self.assertSensor("e_bat_charge_total", 2758.1, 'kWh', data)
Expand Down Expand Up @@ -464,16 +464,16 @@ def test_GW10K_ET_runtime_data_fw1023(self):
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_day', 0, '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_day_exp', 0, 'kWh', data)
self.assertSensor('e_total_imp', 70.3, 'kWh', data)
self.assertSensor('e_day_imp', None, 'kWh', data)
self.assertSensor('e_day_imp', 0, 'kWh', data)
self.assertSensor('e_load_total', 35366.4, 'kWh', data)
self.assertSensor('e_load_day', None, 'kWh', data)
self.assertSensor('e_load_day', 0, '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_charge_day', 0, '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)
Expand Down Expand Up @@ -567,14 +567,14 @@ def test_GW6000_EH_runtime_data(self):
self.assertSensor("e_total_exp", 58.6, 'kWh', data)
self.assertSensor('h_total', 33, 'h', data)
self.assertSensor("e_day_exp", 21.6, 'kWh', data)
self.assertSensor("e_total_imp", None, 'kWh', data)
self.assertSensor("e_day_imp", None, 'kWh', data)
self.assertSensor("e_total_imp", 0, 'kWh', data)
self.assertSensor("e_day_imp", 0, 'kWh', data)
self.assertSensor("e_load_total", 70.1, 'kWh', data)
self.assertSensor("e_load_day", 27.1, 'kWh', data)
self.assertSensor("e_bat_charge_total", None, 'kWh', data)
self.assertSensor("e_bat_charge_day", None, 'kWh', data)
self.assertSensor("e_bat_discharge_total", None, 'kWh', data)
self.assertSensor("e_bat_discharge_day", None, 'kWh', data)
self.assertSensor("e_bat_charge_total", 0, 'kWh', data)
self.assertSensor("e_bat_charge_day", 0, 'kWh', data)
self.assertSensor("e_bat_discharge_total", 0, 'kWh', data)
self.assertSensor("e_bat_discharge_day", 0, 'kWh', data)
self.assertSensor('diagnose_result', 117983303, '', data)
self.assertSensor('diagnose_result_label',
'Battery voltage low, Battery SOC low, Battery SOC in back, Discharge Driver On, Self-use load light, Battery Disconnected, Self-use off, Export power limit set, PF value set, Real power limit set',
Expand Down Expand Up @@ -668,8 +668,8 @@ def test_GEH10_1U_10_runtime_data(self):
self.assertSensor('e_total_exp', 10273.3, 'kWh', data)
self.assertSensor('h_total', 3256, 'h', data)
self.assertSensor('e_day_exp', 16.6, 'kWh', data)
self.assertSensor('e_total_imp', None, 'kWh', data)
self.assertSensor('e_day_imp', None, 'kWh', data)
self.assertSensor('e_total_imp', 0, 'kWh', data)
self.assertSensor('e_day_imp', 0, 'kWh', data)
self.assertSensor('e_load_total', 4393.9, 'kWh', data)
self.assertSensor('e_load_day', 10.7, 'kWh', data)
self.assertSensor('e_bat_charge_total', 141.9, 'kWh', data)
Expand Down Expand Up @@ -881,7 +881,7 @@ def test_GW25K_ET_runtime_data(self):
self.assertSensor('e_bat_charge_total', 91.3, 'kWh', data)
self.assertSensor('e_bat_charge_day', 11.0, 'kWh', data)
self.assertSensor('e_bat_discharge_total', 69.6, 'kWh', data)
self.assertSensor('e_bat_discharge_day', None, 'kWh', data)
self.assertSensor('e_bat_discharge_day', 0, 'kWh', data)
self.assertSensor('diagnose_result', 33816960, '', data)
self.assertSensor('diagnose_result_label',
'BMS: Discharge current low, APP: Discharge current too low, BMS: Charge disabled, PF value set',
Expand Down Expand Up @@ -1152,13 +1152,13 @@ def test_GW29K9_ET_runtime_data(self):
self.assertSensor('h_total', 1175, 'h', data)
self.assertSensor('e_day_exp', 1.2, 'kWh', data)
self.assertSensor('e_total_imp', 8.7, 'kWh', data)
self.assertSensor('e_day_imp', None, 'kWh', data)
self.assertSensor('e_day_imp', 0, 'kWh', data)
self.assertSensor('e_load_total', 10742.2, 'kWh', data)
self.assertSensor('e_load_day', 43.8, 'kWh', data)
self.assertSensor('e_bat_charge_total', None, 'kWh', data)
self.assertSensor('e_bat_charge_day', None, 'kWh', data)
self.assertSensor('e_bat_discharge_total', None, 'kWh', data)
self.assertSensor('e_bat_discharge_day', None, 'kWh', data)
self.assertSensor('e_bat_charge_total', 0, 'kWh', data)
self.assertSensor('e_bat_charge_day', 0, 'kWh', data)
self.assertSensor('e_bat_discharge_total', 0, 'kWh', data)
self.assertSensor('e_bat_discharge_day', 0, 'kWh', data)
self.assertSensor('diagnose_result', 33816782, '', data)
self.assertSensor('diagnose_result_label',
'Battery SOC low, Battery SOC in back, BMS: Discharge disabled, '
Expand Down

0 comments on commit a555e3e

Please sign in to comment.