diff --git a/tests/test_heat_pump.py b/tests/test_heat_pump.py index 1259e9a..ebe4c3a 100644 --- a/tests/test_heat_pump.py +++ b/tests/test_heat_pump.py @@ -36,6 +36,9 @@ def heat_pump(**fields) -> HeatPump: (138, None), (150, HeatPump.State.DHW), (200, HeatPump.State.DEFROSTING), + # counting down to a defrost while still heating at full speed + (202, HeatPump.State.HEATING), + (204, HeatPump.State.DEFROSTING), (239, HeatPump.State.DEFROSTING), (240, None), (1010, HeatPump.State.UPDATING), @@ -108,6 +111,7 @@ def test_cooling_start_conditions_without_a_log(): [ # heat into the water is what heating is for, so the ratio is positive (70, 500, 2000, 4.0), + (202, 500, 2000, 4.0), (150, 500, 2000, 4.0), # heat out of the water is what cooling is for, so that is positive too (132, 521, -2671, pytest.approx(5.126, abs=0.001)), diff --git a/weheat/abstractions/heat_pump.py b/weheat/abstractions/heat_pump.py index f3be9cd..15d8b89 100644 --- a/weheat/abstractions/heat_pump.py +++ b/weheat/abstractions/heat_pump.py @@ -110,8 +110,14 @@ class CoolingStopReason(Enum): CONTACT_SWITCH_OVER = 6 THERMOSTAT_DISABLED = 7 + # The state a heat pump reports in the minutes before a defrost starts. The + # compressor keeps running at full speed and heat still goes into the water, + # and the defrost is sometimes called off without happening. Weheat counts + # it as heating in its own minute and hour data, so it is reported as that. + PRE_DEFROST_STATE = 202 + # The numeric states the heat pump reports while cooling, and while defrosting. - DEFROST_STATES = frozenset({84, 90, 100, 110, 120, *range(200, 240)}) + DEFROST_STATES = frozenset({84, 90, 100, 110, 120, *range(200, 240)}) - {PRE_DEFROST_STATE} COOLING_STATES = frozenset(state.value for state in CoolingState) # Bit masks of the conditions that must all be met before cooling can start. @@ -410,7 +416,7 @@ def heat_pump_state(self) -> Union[State, None]: return self.State.OFFLINE if numeric_state == 40: return self.State.STANDBY - elif numeric_state == 70: + elif numeric_state in (70, self.PRE_DEFROST_STATE): return self.State.HEATING elif numeric_state == self.CoolingState.WATER_CHECK.value: return self.State.WATER_CHECK