Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/test_heat_pump.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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)),
Expand Down
10 changes: 8 additions & 2 deletions weheat/abstractions/heat_pump.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down