From cfc1dcfd5c5ca3f4e98a988effb20715fbe79370 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Sat, 29 Aug 2026 15:54:50 +0200 Subject: [PATCH 01/19] Ignore the generated weheat.egg-info directory The ignore rule still used the old weheat_backend_client package name, so the egg-info directory that an editable install or make build produces showed up as untracked. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_0196E9qDnocL42PxpgJrLc87 --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 6dfe248..ec7e270 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /venv/ /weheat_backend_client.egg-info/ +/weheat.egg-info/ /build/ /.idea/ *.pyc \ No newline at end of file From 68df56fec9b60d716c8ae6cdd0368f130b54f74f Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Sat, 29 Aug 2026 15:54:50 +0200 Subject: [PATCH 02/19] Add the cooling and DHW fields the backend already reports The latest log endpoint returns hqMessageVersion, dhwControlMethod, dhwTargetTemperature, coolingExponentialBackoff, coolingStartConditions, coolingPauseReason, coolingStopReason and lastCoolingTime, but from_dict builds the model from a fixed list of keys, so all eight were silently dropped. Note these were added by hand, matching the generator output, and should be replaced by a regeneration once the OpenAPI spec is updated. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_0196E9qDnocL42PxpgJrLc87 --- weheat/models/raw_heat_pump_log_dto.py | 18 +++++++++++++++++- .../raw_heatpump_log_and_is_online_dto.py | 18 +++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/weheat/models/raw_heat_pump_log_dto.py b/weheat/models/raw_heat_pump_log_dto.py index a4ace93..e173b07 100644 --- a/weheat/models/raw_heat_pump_log_dto.py +++ b/weheat/models/raw_heat_pump_log_dto.py @@ -54,6 +54,14 @@ class RawHeatPumpLogDto(BaseModel): ot_boiler_return_temperature: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Return temperature of the OpenTherm boiler", alias="otBoilerReturnTemperature") central_heating_flow: Optional[StrictInt] = Field(default=None, description="Duty cycle read by pwm pump for central heating circuit", alias="centralHeatingFlow") dhw_flow: Optional[StrictInt] = Field(default=None, description="Duty cycle read by pwm pump for DHW circuit", alias="dhwFlow") + hq_message_version: Optional[StrictInt] = Field(default=None, description="Version of the HQ message format used for this log", alias="hqMessageVersion") + dhw_control_method: Optional[StrictInt] = Field(default=None, description="Control method used for the DHW vessel", alias="dhwControlMethod") + dhw_target_temperature: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Target temperature of the DHW vessel", alias="dhwTargetTemperature") + cooling_exponential_backoff: Optional[StrictInt] = Field(default=None, description="Minutes to wait after a cooling cycle before cooling may start again", alias="coolingExponentialBackoff") + cooling_start_conditions: Optional[StrictInt] = Field(default=None, description="Conditions for starting cooling (bitwise encoded)", alias="coolingStartConditions") + cooling_pause_reason: Optional[StrictInt] = Field(default=None, description="Reason cooling is currently paused", alias="coolingPauseReason") + cooling_stop_reason: Optional[StrictInt] = Field(default=None, description="Reason the last cooling cycle stopped", alias="coolingStopReason") + last_cooling_time: Optional[datetime] = Field(default=None, description="Timestamp of the last time the heat pump was cooling", alias="lastCoolingTime") interval: StrictInt = Field(description="Interval for this log in seconds") input_status: Optional[StrictInt] = Field(default=None, description="Raw input status of the heat pump", alias="inputStatus") current_control_method: Optional[StrictInt] = Field(default=None, description="Raw current control method state of the heat pump", alias="currentControlMethod") @@ -102,7 +110,7 @@ class RawHeatPumpLogDto(BaseModel): debug_variable3: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Optional debug variable that can be set to anything in firmware and will be logged as a float float - 4 bytes", alias="debugVariable3") debug_variable4: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Optional debug variable that can be set to anything in firmware and will be logged as a float float - 4 bytes", alias="debugVariable4") debug_variable5: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Optional debug variable that can be set to anything in firmware and will be logged as a float float - 4 bytes", alias="debugVariable5") - __properties: ClassVar[List[str]] = ["heatPumpId", "timestamp", "state", "controlBridgeStatus", "controlBridgeStatusDecodedWaterPump", "controlBridgeStatusDecodedGasBoiler", "controlBridgeStatusDecodedElectricHeater", "controlBridgeStatusDecodedWaterPump2", "t1", "t2", "tAirIn", "tAirOut", "tWaterIn", "tWaterOut", "tWaterHouseIn", "rpm", "onOffThermostatState", "tRoom", "tRoomTarget", "tThermostatSetpoint", "otBoilerFeedTemperature", "otBoilerReturnTemperature", "centralHeatingFlow", "dhwFlow", "interval", "inputStatus", "currentControlMethod", "signalStrength", "rpmLimiter", "rpmLimiterType", "pCompressorIn", "pCompressorOut", "pCompressorInTarget", "tCompressorIn", "tCompressorOut", "tCompressorInTransient", "tCompressorOutTransient", "deltaTCompressorInSuperheat", "fan", "fanPower", "temperatureErrorIntegral", "thermostatStatus", "otBoilerStatus", "centralHeatingPwmRequestedDutyCycle", "dhwPwmRequestedDutyCycle", "sinr", "error", "errorDecodedDtcNone", "errorDecodedDtcContinue", "errorDecodedDtcCompressorOff", "errorDecodedDtcDefrostForbidden", "errorDecodedDtcRequestService", "errorDecodedDtcUseHeatingCurve", "errorDecodedDtcDhwForbidden", "errorDecodedDtcError", "errorDecodedDtcInactive", "controlBridgeStatusDecodedDhwValve", "tBoard", "tInverter", "compressorPowerLowAccuracy", "valve", "inverterInputVoltage", "indoorUnitHeaterTemperature", "indoorUnitInputCurrent", "coolingStatus", "cmMassPowerIn", "cmMassPowerOut", "debugVariable1", "debugVariable2", "debugVariable3", "debugVariable4", "debugVariable5"] + __properties: ClassVar[List[str]] = ["heatPumpId", "timestamp", "state", "controlBridgeStatus", "controlBridgeStatusDecodedWaterPump", "controlBridgeStatusDecodedGasBoiler", "controlBridgeStatusDecodedElectricHeater", "controlBridgeStatusDecodedWaterPump2", "t1", "t2", "tAirIn", "tAirOut", "tWaterIn", "tWaterOut", "tWaterHouseIn", "rpm", "onOffThermostatState", "tRoom", "tRoomTarget", "tThermostatSetpoint", "otBoilerFeedTemperature", "otBoilerReturnTemperature", "centralHeatingFlow", "dhwFlow", "hqMessageVersion", "dhwControlMethod", "dhwTargetTemperature", "coolingExponentialBackoff", "coolingStartConditions", "coolingPauseReason", "coolingStopReason", "lastCoolingTime", "interval", "inputStatus", "currentControlMethod", "signalStrength", "rpmLimiter", "rpmLimiterType", "pCompressorIn", "pCompressorOut", "pCompressorInTarget", "tCompressorIn", "tCompressorOut", "tCompressorInTransient", "tCompressorOutTransient", "deltaTCompressorInSuperheat", "fan", "fanPower", "temperatureErrorIntegral", "thermostatStatus", "otBoilerStatus", "centralHeatingPwmRequestedDutyCycle", "dhwPwmRequestedDutyCycle", "sinr", "error", "errorDecodedDtcNone", "errorDecodedDtcContinue", "errorDecodedDtcCompressorOff", "errorDecodedDtcDefrostForbidden", "errorDecodedDtcRequestService", "errorDecodedDtcUseHeatingCurve", "errorDecodedDtcDhwForbidden", "errorDecodedDtcError", "errorDecodedDtcInactive", "controlBridgeStatusDecodedDhwValve", "tBoard", "tInverter", "compressorPowerLowAccuracy", "valve", "inverterInputVoltage", "indoorUnitHeaterTemperature", "indoorUnitInputCurrent", "coolingStatus", "cmMassPowerIn", "cmMassPowerOut", "debugVariable1", "debugVariable2", "debugVariable3", "debugVariable4", "debugVariable5"] model_config = { "populate_by_name": True, @@ -522,6 +530,14 @@ def from_dict(cls, obj: Dict) -> Self: "otBoilerReturnTemperature": obj.get("otBoilerReturnTemperature"), "centralHeatingFlow": obj.get("centralHeatingFlow"), "dhwFlow": obj.get("dhwFlow"), + "hqMessageVersion": obj.get("hqMessageVersion"), + "dhwControlMethod": obj.get("dhwControlMethod"), + "dhwTargetTemperature": obj.get("dhwTargetTemperature"), + "coolingExponentialBackoff": obj.get("coolingExponentialBackoff"), + "coolingStartConditions": obj.get("coolingStartConditions"), + "coolingPauseReason": obj.get("coolingPauseReason"), + "coolingStopReason": obj.get("coolingStopReason"), + "lastCoolingTime": obj.get("lastCoolingTime"), "interval": obj.get("interval"), "inputStatus": obj.get("inputStatus"), "currentControlMethod": obj.get("currentControlMethod"), diff --git a/weheat/models/raw_heatpump_log_and_is_online_dto.py b/weheat/models/raw_heatpump_log_and_is_online_dto.py index 5163202..0e8f93a 100644 --- a/weheat/models/raw_heatpump_log_and_is_online_dto.py +++ b/weheat/models/raw_heatpump_log_and_is_online_dto.py @@ -54,6 +54,14 @@ class RawHeatpumpLogAndIsOnlineDto(BaseModel): ot_boiler_return_temperature: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Return temperature of the OpenTherm boiler", alias="otBoilerReturnTemperature") central_heating_flow: Optional[StrictInt] = Field(default=None, description="Duty cycle read by pwm pump for central heating circuit", alias="centralHeatingFlow") dhw_flow: Optional[StrictInt] = Field(default=None, description="Duty cycle read by pwm pump for DHW circuit", alias="dhwFlow") + hq_message_version: Optional[StrictInt] = Field(default=None, description="Version of the HQ message format used for this log", alias="hqMessageVersion") + dhw_control_method: Optional[StrictInt] = Field(default=None, description="Control method used for the DHW vessel", alias="dhwControlMethod") + dhw_target_temperature: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Target temperature of the DHW vessel", alias="dhwTargetTemperature") + cooling_exponential_backoff: Optional[StrictInt] = Field(default=None, description="Minutes to wait after a cooling cycle before cooling may start again", alias="coolingExponentialBackoff") + cooling_start_conditions: Optional[StrictInt] = Field(default=None, description="Conditions for starting cooling (bitwise encoded)", alias="coolingStartConditions") + cooling_pause_reason: Optional[StrictInt] = Field(default=None, description="Reason cooling is currently paused", alias="coolingPauseReason") + cooling_stop_reason: Optional[StrictInt] = Field(default=None, description="Reason the last cooling cycle stopped", alias="coolingStopReason") + last_cooling_time: Optional[datetime] = Field(default=None, description="Timestamp of the last time the heat pump was cooling", alias="lastCoolingTime") interval: StrictInt = Field(description="Interval for this log in seconds") input_status: Optional[StrictInt] = Field(default=None, description="Raw input status of the heat pump", alias="inputStatus") current_control_method: Optional[StrictInt] = Field(default=None, description="Raw current control method state of the heat pump", alias="currentControlMethod") @@ -103,7 +111,7 @@ class RawHeatpumpLogAndIsOnlineDto(BaseModel): debug_variable4: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Optional debug variable that can be set to anything in firmware and will be logged as a float float - 4 bytes", alias="debugVariable4") debug_variable5: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Optional debug variable that can be set to anything in firmware and will be logged as a float float - 4 bytes", alias="debugVariable5") is_online: Optional[StrictBool] = Field(default=None, description="A boolean indicating if the heat pump is currently online", alias="isOnline") - __properties: ClassVar[List[str]] = ["heatPumpId", "timestamp", "state", "controlBridgeStatus", "controlBridgeStatusDecodedWaterPump", "controlBridgeStatusDecodedGasBoiler", "controlBridgeStatusDecodedElectricHeater", "controlBridgeStatusDecodedWaterPump2", "t1", "t2", "tAirIn", "tAirOut", "tWaterIn", "tWaterOut", "tWaterHouseIn", "rpm", "onOffThermostatState", "tRoom", "tRoomTarget", "tThermostatSetpoint", "otBoilerFeedTemperature", "otBoilerReturnTemperature", "centralHeatingFlow", "dhwFlow", "interval", "inputStatus", "currentControlMethod", "signalStrength", "rpmLimiter", "rpmLimiterType", "pCompressorIn", "pCompressorOut", "pCompressorInTarget", "tCompressorIn", "tCompressorOut", "tCompressorInTransient", "tCompressorOutTransient", "deltaTCompressorInSuperheat", "fan", "fanPower", "temperatureErrorIntegral", "thermostatStatus", "otBoilerStatus", "centralHeatingPwmRequestedDutyCycle", "dhwPwmRequestedDutyCycle", "sinr", "error", "errorDecodedDtcNone", "errorDecodedDtcContinue", "errorDecodedDtcCompressorOff", "errorDecodedDtcDefrostForbidden", "errorDecodedDtcRequestService", "errorDecodedDtcUseHeatingCurve", "errorDecodedDtcDhwForbidden", "errorDecodedDtcError", "errorDecodedDtcInactive", "controlBridgeStatusDecodedDhwValve", "tBoard", "tInverter", "compressorPowerLowAccuracy", "valve", "inverterInputVoltage", "indoorUnitHeaterTemperature", "indoorUnitInputCurrent", "coolingStatus", "cmMassPowerIn", "cmMassPowerOut", "debugVariable1", "debugVariable2", "debugVariable3", "debugVariable4", "debugVariable5", "isOnline"] + __properties: ClassVar[List[str]] = ["heatPumpId", "timestamp", "state", "controlBridgeStatus", "controlBridgeStatusDecodedWaterPump", "controlBridgeStatusDecodedGasBoiler", "controlBridgeStatusDecodedElectricHeater", "controlBridgeStatusDecodedWaterPump2", "t1", "t2", "tAirIn", "tAirOut", "tWaterIn", "tWaterOut", "tWaterHouseIn", "rpm", "onOffThermostatState", "tRoom", "tRoomTarget", "tThermostatSetpoint", "otBoilerFeedTemperature", "otBoilerReturnTemperature", "centralHeatingFlow", "dhwFlow", "hqMessageVersion", "dhwControlMethod", "dhwTargetTemperature", "coolingExponentialBackoff", "coolingStartConditions", "coolingPauseReason", "coolingStopReason", "lastCoolingTime", "interval", "inputStatus", "currentControlMethod", "signalStrength", "rpmLimiter", "rpmLimiterType", "pCompressorIn", "pCompressorOut", "pCompressorInTarget", "tCompressorIn", "tCompressorOut", "tCompressorInTransient", "tCompressorOutTransient", "deltaTCompressorInSuperheat", "fan", "fanPower", "temperatureErrorIntegral", "thermostatStatus", "otBoilerStatus", "centralHeatingPwmRequestedDutyCycle", "dhwPwmRequestedDutyCycle", "sinr", "error", "errorDecodedDtcNone", "errorDecodedDtcContinue", "errorDecodedDtcCompressorOff", "errorDecodedDtcDefrostForbidden", "errorDecodedDtcRequestService", "errorDecodedDtcUseHeatingCurve", "errorDecodedDtcDhwForbidden", "errorDecodedDtcError", "errorDecodedDtcInactive", "controlBridgeStatusDecodedDhwValve", "tBoard", "tInverter", "compressorPowerLowAccuracy", "valve", "inverterInputVoltage", "indoorUnitHeaterTemperature", "indoorUnitInputCurrent", "coolingStatus", "cmMassPowerIn", "cmMassPowerOut", "debugVariable1", "debugVariable2", "debugVariable3", "debugVariable4", "debugVariable5", "isOnline"] model_config = { "populate_by_name": True, @@ -523,6 +531,14 @@ def from_dict(cls, obj: Dict) -> Self: "otBoilerReturnTemperature": obj.get("otBoilerReturnTemperature"), "centralHeatingFlow": obj.get("centralHeatingFlow"), "dhwFlow": obj.get("dhwFlow"), + "hqMessageVersion": obj.get("hqMessageVersion"), + "dhwControlMethod": obj.get("dhwControlMethod"), + "dhwTargetTemperature": obj.get("dhwTargetTemperature"), + "coolingExponentialBackoff": obj.get("coolingExponentialBackoff"), + "coolingStartConditions": obj.get("coolingStartConditions"), + "coolingPauseReason": obj.get("coolingPauseReason"), + "coolingStopReason": obj.get("coolingStopReason"), + "lastCoolingTime": obj.get("lastCoolingTime"), "interval": obj.get("interval"), "inputStatus": obj.get("inputStatus"), "currentControlMethod": obj.get("currentControlMethod"), From 11be183372b4cd735dc6cd7117108df8605e3c18 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Sat, 29 Aug 2026 15:55:19 +0200 Subject: [PATCH 03/19] Stop swallowing every error in async_get_energy The bare except set _energy_total to None and returned normally, so callers could not tell a failed fetch from a heat pump with no energy data. In Home Assistant this meant the energy coordinator never reported an update failure and never triggered reauthentication on an expired token; the energy sensors just went unknown. Re-raise like async_get_logs already does. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_0196E9qDnocL42PxpgJrLc87 --- weheat/abstractions/heat_pump.py | 1 + 1 file changed, 1 insertion(+) diff --git a/weheat/abstractions/heat_pump.py b/weheat/abstractions/heat_pump.py index 079eeb9..274f7bc 100644 --- a/weheat/abstractions/heat_pump.py +++ b/weheat/abstractions/heat_pump.py @@ -84,6 +84,7 @@ async def async_get_energy(self, access_token: str) -> None: except Exception as e: self._energy_total = None + raise e def _if_available_and_valid(self, key: str) -> Optional[T]: """Return the value from the last logged value if available and not -1. None otherwise.""" From 44adbb36b2ce7f2a11d61766f70df4c25ba1bb75 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Sat, 29 Aug 2026 15:55:37 +0200 Subject: [PATCH 04/19] Report a positive coefficient of performance while cooling cmMassPowerOut is negative while cooling or defrosting, as heat is removed from the water, so output / input returned a negative COP for every cooling sample. A pump cooling at 521 W in and -2671 W out reported -5.1 instead of 5.1. The test asserted power_output >= 0 unconditionally, which fails as soon as a test pump happens to be cooling, so it now expects the negative output in the cooling and defrosting states and checks the COP stays positive. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_0196E9qDnocL42PxpgJrLc87 --- tests/test_ha_api.py | 8 +++++++- weheat/abstractions/heat_pump.py | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/test_ha_api.py b/tests/test_ha_api.py index 47737f8..1962bac 100644 --- a/tests/test_ha_api.py +++ b/tests/test_ha_api.py @@ -84,7 +84,13 @@ async def test_hp_log(api_fixture, uuid): if heatpump.thermostat_room_temperature is not None: #thermostat may be disconnected assert heatpump.thermostat_room_temperature >= -1 assert heatpump.power_input is None or heatpump.power_input >= 0 - assert heatpump.power_output is None or heatpump.power_output >= 0 + if heatpump.heat_pump_state in (HeatPump.State.COOLING, HeatPump.State.DEFROSTING): + # heat is removed from the water in these states, so the output power is negative + assert heatpump.power_output is None or heatpump.power_output <= 0 + else: + assert heatpump.power_output is None or heatpump.power_output >= 0 + # the coefficient of performance is a positive ratio in every state + assert heatpump.cop is None or heatpump.cop >= 0 assert heatpump.compressor_rpm >= 0 assert heatpump.heat_pump_state in HeatPump.State assert heatpump.energy_in_heating >= 0 diff --git a/weheat/abstractions/heat_pump.py b/weheat/abstractions/heat_pump.py index 274f7bc..6bddf82 100644 --- a/weheat/abstractions/heat_pump.py +++ b/weheat/abstractions/heat_pump.py @@ -210,7 +210,9 @@ def cop(self) -> Union[float, None]: return None if input > 0: - return output / input + # While cooling or defrosting the output power is negative, as heat is removed from + # the water. The amount of energy moved per unit of input is still a positive ratio. + return abs(output) / input return 0 From e861a9dafa2360245e463be5b2370873f9f301fe Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Sat, 29 Aug 2026 15:55:46 +0200 Subject: [PATCH 05/19] Expose the cooling state, control method and DHW target Adds properties for the log fields the models now carry: - is_online, so callers can tell a stale log from a live one - dhw_target_temperature and last_cooling_time - cooling_pause_reason, cooling_stop_reason and current_control_method, decoded through enums instead of raw codes - cooling_start_conditions, decoding the bitwise coolingStartConditions into a named flag per condition - cooling_backoff and cooling_available_from, the moment the wait time after a cooling cycle expires Unknown codes decode to None rather than raising, so a backend that grows a new value does not break existing callers. The CoolingPauseReason values and the condition bit masks are taken from the portal. The CoolingStopReason values are inferred from the order the portal lists them in and should be confirmed against the backend before release. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_0196E9qDnocL42PxpgJrLc87 --- weheat/abstractions/heat_pump.py | 131 ++++++++++++++++++++++++++++++- 1 file changed, 129 insertions(+), 2 deletions(-) diff --git a/weheat/abstractions/heat_pump.py b/weheat/abstractions/heat_pump.py index 6bddf82..b44e038 100644 --- a/weheat/abstractions/heat_pump.py +++ b/weheat/abstractions/heat_pump.py @@ -1,7 +1,7 @@ """Weheat heat pump abstraction from the API.""" -from datetime import datetime +from datetime import datetime, timedelta from enum import Enum, auto -from typing import TypeVar, Union, Optional, cast +from typing import Dict, TypeVar, Union, Optional, cast import aiohttp @@ -30,6 +30,54 @@ class State(Enum): SELF_TEST = auto() MANUAL_CONTROL = auto() + class CoolingPauseReason(Enum): + NONE = 0 + ROOM_TEMPERATURE_TOO_LOW = 1 + OUTSIDE_TEMPERATURE_TOO_LOW = 2 + OUTSIDE_COLDER_THAN_WATER_TEMPERATURE = 3 + WATER_TEMPERATURE_BELOW_SETPOINT = 4 + HEAT_PUMP_CONTROL = 5 + WATER_TEMPERATURE_BELOW_DEWPOINT = 6 + CONTACT_BLOCKED = 7 + DEMAND = 8 + + class ControlMethod(Enum): + NONE = 0 + HEATING_CURVE = 1 + ON_OFF_THERMOSTAT = 2 + BASE_OPEN_THERM = 3 + SMART_OPEN_THERM = 4 + CLOUD_THERMOSTAT = 5 + MANUAL_POWER = 6 + AUTO_INPUT_SELECT = 7 + MANUAL_SETPOINT = 8 + WEHEAT_INTELLIGENCE = 9 + + class CoolingStopReason(Enum): + NONE = 0 + DTC = 1 + CONTROL_METHOD = 2 + NO_INDOOR_UNIT_COMMUNICATION = 3 + HEAT_PUMP_CONTROL = 4 + COOLING_CONTROL = 5 + CONTACT_SWITCH_OVER = 6 + THERMOSTAT_DISABLED = 7 + + # Bit masks of the conditions that must all be met before cooling can start. + COOLING_START_CONDITION_BITS = { + "control_method": 1, + "dtc": 2, + "outside_air_temperature": 4, + "inside_temperature": 8, + "indoor_unit_connected": 16, + "water_to_air": 32, + "demand": 64, + "water_temperature": 128, + "contact_not_blocked": 256, + "exponential_backoff": 512, + "heat_cool_delay": 1024, + } + def __init__(self, api_url: str, uuid: str, client_session: aiohttp.ClientSession | None = None) -> None: self._api_url = api_url self._uuid = uuid @@ -131,6 +179,11 @@ def raw_content(self) -> Optional[dict]: raw.update(vars(self._energy_total)) return raw or None + @property + def is_online(self) -> Union[bool, None]: + """Whether the heat pump was still reporting to the backend at the time of the last log.""" + return self._if_available("is_online") + @property def water_inlet_temperature(self) -> Union[float, None]: """The heat pump water inlet temperature.""" @@ -196,6 +249,11 @@ def dhw_bottom_temperature(self) -> Union[float, None]: """The DHW vessel bottom temperature.""" return self._if_available("t2") + @property + def dhw_target_temperature(self) -> Union[float, None]: + """The DHW vessel target temperature.""" + return self._if_available_and_valid("dhw_target_temperature") + @property def cop(self) -> Union[float, None]: """ @@ -281,6 +339,75 @@ def heat_pump_state(self) -> Union[State, None]: return self.State.DEFROSTING return None + @property + def last_cooling_time(self) -> Union[datetime, None]: + """The last completed cooling cycle, which the restart delay is counted from. + + This is not updated while a cooling cycle is running, so during cooling it still + refers to the cycle before it. + """ + return cast(Optional[datetime], self._if_available("last_cooling_time")) + + @property + def current_control_method(self) -> Union["HeatPump.ControlMethod", None]: + """The control method the heat pump is currently running on.""" + value = self._if_available("current_control_method") + if value is None: + return None + try: + return self.ControlMethod(value) + except ValueError: + # The backend may report methods this version does not know about yet. + return None + + @property + def cooling_pause_reason(self) -> Union["HeatPump.CoolingPauseReason", None]: + """The reason cooling is currently held off.""" + value = self._if_available("cooling_pause_reason") + if value is None: + return None + try: + return self.CoolingPauseReason(value) + except ValueError: + # The backend may report reasons this version does not know about yet. + return None + + @property + def cooling_stop_reason(self) -> Union["HeatPump.CoolingStopReason", None]: + """The reason the last cooling cycle was stopped.""" + value = self._if_available("cooling_stop_reason") + if value is None: + return None + try: + return self.CoolingStopReason(value) + except ValueError: + # The backend may report reasons this version does not know about yet. + return None + + @property + def cooling_backoff(self) -> Union[int, None]: + """The minutes to wait after a cooling cycle before cooling may start again.""" + return self._if_available("cooling_exponential_backoff") + + @property + def cooling_available_from(self) -> Union[datetime, None]: + """The moment the wait time after the last cooling cycle expires.""" + last_cooling_time = self.last_cooling_time + if last_cooling_time is None: + return None + return last_cooling_time + timedelta(minutes=self.cooling_backoff or 0) + + @property + def cooling_start_conditions(self) -> Union[Dict[str, bool], None]: + """Each condition for starting cooling, and whether it is currently met.""" + value = self._if_available("cooling_start_conditions") + if value is None: + return None + return { + name: bool(value & bit) + for name, bit in self.COOLING_START_CONDITION_BITS.items() + } + @staticmethod def _pwm_to_volume(pwm: float, max: float) -> Union[float, None]: """Calculate PWM to Volume in m3/h based on the max available volume""" From afaf3babc76b5cd52341748411ef25c47c8ed27b Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Mon, 31 Aug 2026 12:21:16 +0200 Subject: [PATCH 06/19] Use the real list of defrost states The portal ships the defrost states as an explicit list, which the range check got wrong at both ends: states 84, 90, 100, 110 and 120 are defrost states but were reported as an unknown state, and 240 is not one but was reported as defrosting. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_0196E9qDnocL42PxpgJrLc87 --- weheat/abstractions/heat_pump.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/weheat/abstractions/heat_pump.py b/weheat/abstractions/heat_pump.py index b44e038..88b2d5d 100644 --- a/weheat/abstractions/heat_pump.py +++ b/weheat/abstractions/heat_pump.py @@ -63,6 +63,9 @@ class CoolingStopReason(Enum): CONTACT_SWITCH_OVER = 6 THERMOSTAT_DISABLED = 7 + # The numeric states the heat pump reports while defrosting. + DEFROST_STATES = frozenset({84, 90, 100, 110, 120, *range(200, 240)}) + # Bit masks of the conditions that must all be met before cooling can start. COOLING_START_CONDITION_BITS = { "control_method": 1, @@ -335,7 +338,7 @@ def heat_pump_state(self) -> Union[State, None]: return self.State.SELF_TEST elif numeric_state == 180: return self.State.MANUAL_CONTROL - elif numeric_state >= 200 and numeric_state <= 240: + elif numeric_state in self.DEFROST_STATES: return self.State.DEFROSTING return None From a98edc376a5604e1c8414b5d0cc04d7048eea0b4 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Mon, 31 Aug 2026 12:24:06 +0200 Subject: [PATCH 07/19] Decode the cooling sub states and the firmware update state The portal defines cooling states 130 to 137 and a heat pump status enum. Use those instead of guessing: - cooling_state exposes the sub state, so callers can tell starting, active, stopping, pausing and water check apart - 138 and 139 are no longer reported as cooling, as they are not cooling states - state 136 now produces State.WATER_CHECK, which no numeric value produced before even though the state existed - state 1010 now produces the new State.UPDATING, for a firmware update Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_0196E9qDnocL42PxpgJrLc87 --- weheat/abstractions/heat_pump.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/weheat/abstractions/heat_pump.py b/weheat/abstractions/heat_pump.py index 88b2d5d..fc19df9 100644 --- a/weheat/abstractions/heat_pump.py +++ b/weheat/abstractions/heat_pump.py @@ -29,6 +29,17 @@ class State(Enum): DEFROSTING = auto() SELF_TEST = auto() MANUAL_CONTROL = auto() + UPDATING = auto() + + class CoolingState(Enum): + IDLE = 130 + STARTING = 131 + ACTIVE = 132 + STOPPING = 133 + STANDBY = 134 + PAUSING = 135 + WATER_CHECK = 136 + STANDBY_RUN_CP = 137 class CoolingPauseReason(Enum): NONE = 0 @@ -63,8 +74,9 @@ class CoolingStopReason(Enum): CONTACT_SWITCH_OVER = 6 THERMOSTAT_DISABLED = 7 - # The numeric states the heat pump reports while defrosting. + # The numeric states the heat pump reports while cooling, and while defrosting. DEFROST_STATES = frozenset({84, 90, 100, 110, 120, *range(200, 240)}) + COOLING_STATES = frozenset(state.value for state in CoolingState) # Bit masks of the conditions that must all be met before cooling can start. COOLING_START_CONDITION_BITS = { @@ -328,7 +340,9 @@ def heat_pump_state(self) -> Union[State, None]: return self.State.STANDBY elif numeric_state == 70: return self.State.HEATING - elif numeric_state >= 130 and numeric_state < 140: + elif numeric_state == self.CoolingState.WATER_CHECK.value: + return self.State.WATER_CHECK + elif numeric_state in self.COOLING_STATES: return self.State.COOLING elif numeric_state == 150: return self.State.DHW @@ -338,6 +352,8 @@ def heat_pump_state(self) -> Union[State, None]: return self.State.SELF_TEST elif numeric_state == 180: return self.State.MANUAL_CONTROL + elif numeric_state == 1010: + return self.State.UPDATING elif numeric_state in self.DEFROST_STATES: return self.State.DEFROSTING return None @@ -363,6 +379,17 @@ def current_control_method(self) -> Union["HeatPump.ControlMethod", None]: # The backend may report methods this version does not know about yet. return None + @property + def cooling_state(self) -> Union["HeatPump.CoolingState", None]: + """The cooling sub state, only set while the heat pump is in a cooling state.""" + value = self._if_available("state") + if value is None: + return None + try: + return self.CoolingState(value) + except ValueError: + return None + @property def cooling_pause_reason(self) -> Union["HeatPump.CoolingPauseReason", None]: """The reason cooling is currently held off.""" From c90c5e7fdd0fc944f9de2ff6c63d5d41a6108183 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Mon, 31 Aug 2026 13:31:51 +0200 Subject: [PATCH 08/19] Derive the cooling status in the library The heat pump only reports a cooling state during a cooling cycle. Outside one, whether cooling is paused, stopped or waiting for its start conditions follows from the pause and stop reasons, which is vendor behaviour that belongs next to the rest of the decoding rather than in each consumer. cooling_status returns None for a heat pump that does not report cooling at all, so consumers can tell an unsupported heat pump from one that is simply not cooling right now. Also adds unit tests for the decoding, which needed the API options in the test fixture to become optional so the tests can run without credentials. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_0196E9qDnocL42PxpgJrLc87 --- tests/conftest.py | 22 ++++-- tests/test_heat_pump.py | 123 +++++++++++++++++++++++++++++++ weheat/abstractions/heat_pump.py | 35 +++++++++ 3 files changed, 173 insertions(+), 7 deletions(-) create mode 100644 tests/test_heat_pump.py diff --git a/tests/conftest.py b/tests/conftest.py index 71d9121..1e42620 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,5 @@ import pytest from dataclasses import dataclass -from keycloak import KeycloakOpenID def pytest_addoption(parser): # These are used by the STK500 interface @@ -10,42 +9,42 @@ def pytest_addoption(parser): action="store", type=str, help="API url", - required=True, + default=None, ) parser.addoption( "--auth_url", action="store", type=str, help="Authentication url", - required=True, + default=None, ) parser.addoption( "--client_id", action="store", type=str, help="Client id", - required=True, + default=None, ) parser.addoption( "--client_secret", action="store", type=str, help="Client secret", - required=True, + default=None, ) parser.addoption( "--user", action="store", type=str, help="User email", - required=True, + default=None, ) parser.addoption( "--password", action="store", type=str, help="User password", - required=True, + default=None, ) @@ -63,8 +62,17 @@ class ApiInfo: access_token: str +OPTIONS = ("api_url", "auth_url", "client_id", "client_secret", "user", "password") + + @pytest.fixture() def api_fixture(request): + missing = [name for name in OPTIONS if not request.config.getoption(f"--{name}")] + if missing: + pytest.skip(f"needs the API options: {', '.join('--' + name for name in missing)}") + + from keycloak import KeycloakOpenID + api_info = ApiInfo(request.config.getoption('--api_url'), request.config.getoption('--auth_url'), request.config.getoption('--client_id'), request.config.getoption('--client_secret'), request.config.getoption('--user'), request.config.getoption('--password'), "") diff --git a/tests/test_heat_pump.py b/tests/test_heat_pump.py new file mode 100644 index 0000000..9c87b57 --- /dev/null +++ b/tests/test_heat_pump.py @@ -0,0 +1,123 @@ +"""Unit tests for the decoding the HeatPump abstraction does on a log. + +These run without API credentials, unlike the tests in test_ha_api.py. +""" +import pytest + +from weheat.abstractions.heat_pump import HeatPump +from weheat.models.raw_heatpump_log_and_is_online_dto import RawHeatpumpLogAndIsOnlineDto + +BASE_LOG = { + "heat_pump_id": "0000-1111-2222-3333", + "timestamp": "2026-08-31T10:00:00+00:00", + "interval": 15, +} + + +def heat_pump(**fields) -> HeatPump: + """Build a heat pump holding a log with the given fields.""" + pump = HeatPump("https://example.invalid", "0000-1111-2222-3333") + pump._last_log = RawHeatpumpLogAndIsOnlineDto.model_validate({**BASE_LOG, **fields}) + return pump + + +@pytest.mark.parametrize( + ("state", "expected"), + [ + (1, HeatPump.State.OFFLINE), + (40, HeatPump.State.STANDBY), + (70, HeatPump.State.HEATING), + (84, HeatPump.State.DEFROSTING), + (90, HeatPump.State.DEFROSTING), + (120, HeatPump.State.DEFROSTING), + (130, HeatPump.State.COOLING), + (136, HeatPump.State.WATER_CHECK), + (137, HeatPump.State.COOLING), + (138, None), + (150, HeatPump.State.DHW), + (200, HeatPump.State.DEFROSTING), + (239, HeatPump.State.DEFROSTING), + (240, None), + (1010, HeatPump.State.UPDATING), + ], +) +def test_heat_pump_state(state, expected): + """Test the numeric state maps to the state the heat pump is in.""" + assert heat_pump(state=state).heat_pump_state is expected + + +@pytest.mark.parametrize( + ("fields", "expected"), + [ + ({"state": 132, "cooling_pause_reason": 0}, HeatPump.CoolingStatus.ACTIVE), + ({"state": 131, "cooling_pause_reason": 0}, HeatPump.CoolingStatus.STARTING), + ({"state": 136, "cooling_pause_reason": 0}, HeatPump.CoolingStatus.WATER_CHECK), + ({"state": 40, "cooling_pause_reason": 0}, HeatPump.CoolingStatus.WAITING), + ({"state": 40, "cooling_pause_reason": 4}, HeatPump.CoolingStatus.PAUSED), + ( + {"state": 40, "cooling_pause_reason": 0, "cooling_stop_reason": 1}, + HeatPump.CoolingStatus.STOPPED, + ), + # a pause reason only counts while the heat pump is in standby + ({"state": 70, "cooling_pause_reason": 4}, HeatPump.CoolingStatus.WAITING), + # a heat pump that does not do cooling reports no cooling fields at all + ({"state": 70}, None), + ], +) +def test_cooling_status(fields, expected): + """Test the cooling status says what the heat pump is doing, or why it is not.""" + assert heat_pump(**fields).cooling_status is expected + + +def test_cooling_start_conditions(): + """Test the start conditions decode to a flag per condition.""" + # every condition met except the outside air temperature + conditions = heat_pump(cooling_start_conditions=2043).cooling_start_conditions + + assert conditions["outside_air_temperature"] is False + assert conditions["demand"] is True + assert sum(conditions.values()) == len(HeatPump.COOLING_START_CONDITION_BITS) - 1 + + +def test_cooling_start_conditions_without_a_log(): + """Test a heat pump that reports no start conditions decodes to nothing.""" + assert heat_pump().cooling_start_conditions is None + + +@pytest.mark.parametrize( + ("power_in", "power_out", "expected"), + [ + (500, 2000, 4.0), + # while cooling the output power is negative, the ratio stays positive + (521, -2671, pytest.approx(5.126, abs=0.001)), + (0, 2000, 0), + ], +) +def test_cop(power_in, power_out, expected): + """Test the coefficient of performance is a positive ratio in every state.""" + pump = heat_pump(cm_mass_power_in=power_in, cm_mass_power_out=power_out) + + assert pump.cop == expected + + +def test_cooling_available_from(): + """Test the restart delay is counted from the last cooling cycle.""" + pump = heat_pump( + last_cooling_time="2026-08-31T09:00:00+00:00", cooling_exponential_backoff=180 + ) + + assert pump.cooling_available_from.isoformat() == "2026-08-31T12:00:00+00:00" + + +def test_cooling_available_from_before_any_cooling(): + """Test there is no restart delay before the heat pump has ever cooled.""" + assert heat_pump(cooling_exponential_backoff=180).cooling_available_from is None + + +@pytest.mark.parametrize("code", [99, -1]) +def test_unknown_codes_decode_to_nothing(code): + """Test a code this version does not know does not raise.""" + pump = heat_pump(cooling_pause_reason=code, cooling_stop_reason=code) + + assert pump.cooling_pause_reason is None + assert pump.cooling_stop_reason is None diff --git a/weheat/abstractions/heat_pump.py b/weheat/abstractions/heat_pump.py index fc19df9..9b4e6c5 100644 --- a/weheat/abstractions/heat_pump.py +++ b/weheat/abstractions/heat_pump.py @@ -41,6 +41,21 @@ class CoolingState(Enum): WATER_CHECK = 136 STANDBY_RUN_CP = 137 + class CoolingStatus(Enum): + """What the heat pump is doing about cooling, or why it is not cooling.""" + + IDLE = auto() + STARTING = auto() + ACTIVE = auto() + STOPPING = auto() + STANDBY = auto() + PAUSING = auto() + WATER_CHECK = auto() + STANDBY_RUN_CP = auto() + PAUSED = auto() + STOPPED = auto() + WAITING = auto() + class CoolingPauseReason(Enum): NONE = 0 ROOM_TEMPERATURE_TOO_LOW = 1 @@ -390,6 +405,26 @@ def cooling_state(self) -> Union["HeatPump.CoolingState", None]: except ValueError: return None + @property + def cooling_status(self) -> Union["HeatPump.CoolingStatus", None]: + """What the heat pump is doing about cooling, or why it is not cooling. + + The heat pump only reports a cooling state during a cooling cycle, so + outside one this reports whether cooling is paused, stopped, or waiting + for its start conditions. None when the heat pump does not do cooling. + """ + cooling_state = self.cooling_state + if cooling_state is not None: + return self.CoolingStatus[cooling_state.name] + if self._if_available("cooling_pause_reason") is None: + return None + if self.heat_pump_state is self.State.STANDBY: + if self.cooling_pause_reason not in (None, self.CoolingPauseReason.NONE): + return self.CoolingStatus.PAUSED + if self.cooling_stop_reason not in (None, self.CoolingStopReason.NONE): + return self.CoolingStatus.STOPPED + return self.CoolingStatus.WAITING + @property def cooling_pause_reason(self) -> Union["HeatPump.CoolingPauseReason", None]: """The reason cooling is currently held off.""" From 2de399f4151e48aa9f91c06d298f747412175bbc Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Tue, 1 Sep 2026 19:35:12 +0200 Subject: [PATCH 09/19] Update weheat/abstractions/heat_pump.py Co-authored-by: jesperraemaekers <146726232+jesperraemaekers@users.noreply.github.com> --- weheat/abstractions/heat_pump.py | 1 - 1 file changed, 1 deletion(-) diff --git a/weheat/abstractions/heat_pump.py b/weheat/abstractions/heat_pump.py index 9b4e6c5..21d2904 100644 --- a/weheat/abstractions/heat_pump.py +++ b/weheat/abstractions/heat_pump.py @@ -77,7 +77,6 @@ class ControlMethod(Enum): MANUAL_POWER = 6 AUTO_INPUT_SELECT = 7 MANUAL_SETPOINT = 8 - WEHEAT_INTELLIGENCE = 9 class CoolingStopReason(Enum): NONE = 0 From d0fd5e7fce0a95b2679ea4ea57c26dc149d4cf25 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Wed, 2 Sep 2026 09:06:13 +0200 Subject: [PATCH 10/19] Decode the cooling status the heat pump reports The cooling_status log field carries the firmware cooling status enum, so map it rather than leaving it as a raw code. The derived value that says what the heat pump is doing about cooling had taken that name, and is now cooling_activity. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_0196E9qDnocL42PxpgJrLc87 --- tests/test_heat_pump.py | 37 ++++++++++++++++++++++++-------- weheat/abstractions/heat_pump.py | 31 +++++++++++++++++++++----- 2 files changed, 54 insertions(+), 14 deletions(-) diff --git a/tests/test_heat_pump.py b/tests/test_heat_pump.py index 9c87b57..5bbb723 100644 --- a/tests/test_heat_pump.py +++ b/tests/test_heat_pump.py @@ -49,24 +49,43 @@ def test_heat_pump_state(state, expected): @pytest.mark.parametrize( ("fields", "expected"), [ - ({"state": 132, "cooling_pause_reason": 0}, HeatPump.CoolingStatus.ACTIVE), - ({"state": 131, "cooling_pause_reason": 0}, HeatPump.CoolingStatus.STARTING), - ({"state": 136, "cooling_pause_reason": 0}, HeatPump.CoolingStatus.WATER_CHECK), - ({"state": 40, "cooling_pause_reason": 0}, HeatPump.CoolingStatus.WAITING), - ({"state": 40, "cooling_pause_reason": 4}, HeatPump.CoolingStatus.PAUSED), + ({"state": 132, "cooling_pause_reason": 0}, HeatPump.CoolingActivity.ACTIVE), + ({"state": 131, "cooling_pause_reason": 0}, HeatPump.CoolingActivity.STARTING), + ({"state": 136, "cooling_pause_reason": 0}, HeatPump.CoolingActivity.WATER_CHECK), + ({"state": 40, "cooling_pause_reason": 0}, HeatPump.CoolingActivity.WAITING), + ({"state": 40, "cooling_pause_reason": 4}, HeatPump.CoolingActivity.PAUSED), ( {"state": 40, "cooling_pause_reason": 0, "cooling_stop_reason": 1}, - HeatPump.CoolingStatus.STOPPED, + HeatPump.CoolingActivity.STOPPED, ), # a pause reason only counts while the heat pump is in standby - ({"state": 70, "cooling_pause_reason": 4}, HeatPump.CoolingStatus.WAITING), + ({"state": 70, "cooling_pause_reason": 4}, HeatPump.CoolingActivity.WAITING), # a heat pump that does not do cooling reports no cooling fields at all ({"state": 70}, None), ], ) -def test_cooling_status(fields, expected): +def test_cooling_activity(fields, expected): """Test the cooling status says what the heat pump is doing, or why it is not.""" - assert heat_pump(**fields).cooling_status is expected + assert heat_pump(**fields).cooling_activity is expected + + +@pytest.mark.parametrize( + ("status", "expected"), + [ + (0, HeatPump.CoolingStatus.IDLE), + (2, HeatPump.CoolingStatus.ACTIVE), + (4, HeatPump.CoolingStatus.STANDBY), + (99, None), + ], +) +def test_cooling_status(status, expected): + """Test the cooling status the heat pump reports in its log.""" + assert heat_pump(cooling_status=status).cooling_status is expected + + +def test_cooling_status_when_not_reported(): + """Test a heat pump that does not report a cooling status decodes to nothing.""" + assert heat_pump(state=40).cooling_status is None def test_cooling_start_conditions(): diff --git a/weheat/abstractions/heat_pump.py b/weheat/abstractions/heat_pump.py index 21d2904..de118e8 100644 --- a/weheat/abstractions/heat_pump.py +++ b/weheat/abstractions/heat_pump.py @@ -41,7 +41,7 @@ class CoolingState(Enum): WATER_CHECK = 136 STANDBY_RUN_CP = 137 - class CoolingStatus(Enum): + class CoolingActivity(Enum): """What the heat pump is doing about cooling, or why it is not cooling.""" IDLE = auto() @@ -56,6 +56,15 @@ class CoolingStatus(Enum): STOPPED = auto() WAITING = auto() + class CoolingStatus(Enum): + """The cooling status the heat pump reports in its log.""" + + IDLE = 0 + STARTING = 1 + ACTIVE = 2 + STOPPING = 3 + STANDBY = 4 + class CoolingPauseReason(Enum): NONE = 0 ROOM_TEMPERATURE_TOO_LOW = 1 @@ -406,6 +415,18 @@ def cooling_state(self) -> Union["HeatPump.CoolingState", None]: @property def cooling_status(self) -> Union["HeatPump.CoolingStatus", None]: + """The cooling status the heat pump reports, if it reports one.""" + value = self._if_available("cooling_status") + if value is None: + return None + try: + return self.CoolingStatus(value) + except ValueError: + # The backend may report a status this version does not know about yet. + return None + + @property + def cooling_activity(self) -> Union["HeatPump.CoolingActivity", None]: """What the heat pump is doing about cooling, or why it is not cooling. The heat pump only reports a cooling state during a cooling cycle, so @@ -414,15 +435,15 @@ def cooling_status(self) -> Union["HeatPump.CoolingStatus", None]: """ cooling_state = self.cooling_state if cooling_state is not None: - return self.CoolingStatus[cooling_state.name] + return self.CoolingActivity[cooling_state.name] if self._if_available("cooling_pause_reason") is None: return None if self.heat_pump_state is self.State.STANDBY: if self.cooling_pause_reason not in (None, self.CoolingPauseReason.NONE): - return self.CoolingStatus.PAUSED + return self.CoolingActivity.PAUSED if self.cooling_stop_reason not in (None, self.CoolingStopReason.NONE): - return self.CoolingStatus.STOPPED - return self.CoolingStatus.WAITING + return self.CoolingActivity.STOPPED + return self.CoolingActivity.WAITING @property def cooling_pause_reason(self) -> Union["HeatPump.CoolingPauseReason", None]: From 47de501029e53fe11424e18bbe0d04d5c5b90066 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Wed, 2 Sep 2026 09:11:25 +0200 Subject: [PATCH 11/19] Bump version to 2026.9.2 Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_0196E9qDnocL42PxpgJrLc87 --- pyproject.toml | 2 +- setup.py | 2 +- weheat/__init__.py | 2 +- weheat/api_client.py | 2 +- weheat/configuration.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a470bec..7d7e940 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "weheat" -version = "2026.4.8" +version = "2026.9.2" description = "Weheat Backend" authors = ["Jesper Raemaekers ", "Kjell van Straaten "] license = "MIT" diff --git a/setup.py b/setup.py index a5b3151..e2f5a96 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ # prerequisite: setuptools # http://pypi.python.org/pypi/setuptools NAME = "weheat" -VERSION = "2026.4.8" +VERSION = "2026.9.2" PYTHON_REQUIRES = ">=3.7" REQUIRES = [ "urllib3 >= 1.25.3, < 3.0.0", diff --git a/weheat/__init__.py b/weheat/__init__.py index cd0b2da..1e43f6d 100644 --- a/weheat/__init__.py +++ b/weheat/__init__.py @@ -14,7 +14,7 @@ """ # noqa: E501 -__version__ = "2026.4.8" +__version__ = "2026.9.2" # import apis into sdk package from weheat.api.energy_log_api import EnergyLogApi diff --git a/weheat/api_client.py b/weheat/api_client.py index 15ba96b..1d2c365 100644 --- a/weheat/api_client.py +++ b/weheat/api_client.py @@ -86,7 +86,7 @@ def __init__( self.default_headers[header_name] = header_value self.cookie = cookie # Set default User-Agent. - self.user_agent = 'OpenAPI-Generator/2026.4.8/python' + self.user_agent = 'OpenAPI-Generator/2026.9.2/python' self.client_side_validation = configuration.client_side_validation async def __aenter__(self): diff --git a/weheat/configuration.py b/weheat/configuration.py index 160a41f..59d77cf 100644 --- a/weheat/configuration.py +++ b/weheat/configuration.py @@ -381,7 +381,7 @@ def to_debug_report(self): "OS: {env}\n"\ "Python Version: {pyversion}\n"\ "Version of the API: v1\n"\ - "SDK Package Version: 2026.4.8".\ + "SDK Package Version: 2026.9.2".\ format(env=sys.platform, pyversion=sys.version) def get_host_settings(self): From 8e638a25c4ac1b773db2a1605d972a4118c16127 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Wed, 2 Sep 2026 09:14:30 +0200 Subject: [PATCH 12/19] Decode recorded API responses in the tests from_dict builds the log model from a fixed list of keys, so a field the backend starts reporting is dropped without any error. Decoding a recorded response and comparing the keys back catches that, which is how the eight cooling and DHW fields went unnoticed until someone read a log by hand. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_0196E9qDnocL42PxpgJrLc87 --- tests/fixtures/log_latest_cooling.json | 40 +++++++++++++++++++ tests/test_fixtures.py | 53 ++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 tests/fixtures/log_latest_cooling.json create mode 100644 tests/test_fixtures.py diff --git a/tests/fixtures/log_latest_cooling.json b/tests/fixtures/log_latest_cooling.json new file mode 100644 index 0000000..1a3048c --- /dev/null +++ b/tests/fixtures/log_latest_cooling.json @@ -0,0 +1,40 @@ +{ + "heatPumpId": "00000000-0000-4000-8000-000000000000", + "timestamp": "2026-08-29T12:44:05.9700858Z", + "state": 132, + "controlBridgeStatus": 4286582803, + "controlBridgeStatusDecodedWaterPump": true, + "controlBridgeStatusDecodedDhwValve": true, + "controlBridgeStatusDecodedGasBoiler": false, + "controlBridgeStatusDecodedElectricHeater": false, + "controlBridgeStatusDecodedWaterPump2": true, + "inputStatus": 29, + "t1": 54.4, + "t2": 53.5, + "tAirIn": 23, + "tAirOut": 25, + "tWaterIn": 20.9, + "tWaterOut": 18.5, + "tWaterHouseIn": 19.2, + "rpm": 900, + "cmMassPowerIn": 521, + "cmMassPowerOut": -2671, + "onOffThermostatState": 0, + "tRoom": 22.1, + "tRoomTarget": 21, + "tThermostatSetpoint": 18, + "otBoilerFeedTemperature": null, + "otBoilerReturnTemperature": null, + "centralHeatingFlow": 48, + "dhwFlow": 2, + "hqMessageVersion": 1, + "dhwControlMethod": 1, + "dhwTargetTemperature": 55, + "coolingExponentialBackoff": 60, + "coolingStartConditions": 1983, + "coolingPauseReason": 4, + "coolingStopReason": 0, + "lastCoolingTime": "2026-08-29T10:32:28Z", + "interval": 15, + "isOnline": true +} diff --git a/tests/test_fixtures.py b/tests/test_fixtures.py new file mode 100644 index 0000000..3730b30 --- /dev/null +++ b/tests/test_fixtures.py @@ -0,0 +1,53 @@ +"""Tests that decode recorded API responses. + +The fixtures are real responses with identifying fields replaced. They guard +against the generated models silently dropping fields the backend has started +reporting, which the models do because from_dict builds from a fixed key list. +""" +import json +import pathlib + +import pytest + +from weheat.abstractions.heat_pump import HeatPump +from weheat.models.raw_heatpump_log_and_is_online_dto import RawHeatpumpLogAndIsOnlineDto + +FIXTURES = pathlib.Path(__file__).parent / "fixtures" + + +def load(name: str) -> dict: + """Return the recorded response with the given name.""" + return json.loads((FIXTURES / name).read_text()) + + +@pytest.mark.parametrize("name", [p.name for p in sorted(FIXTURES.glob("log_*.json"))]) +def test_no_log_field_is_dropped(name): + """Test the log model keeps every field the backend sent. + + from_dict picks keys one by one, so a field the backend adds is discarded + without any error until it is added to the model as well. + """ + payload = load(name) + + decoded = RawHeatpumpLogAndIsOnlineDto.from_dict(payload).to_dict() + + assert not set(payload) - set(decoded) + + +def test_cooling_log(): + """Test a log recorded while the heat pump was cooling.""" + pump = HeatPump("https://example.invalid", "heat-pump") + pump._last_log = RawHeatpumpLogAndIsOnlineDto.from_dict(load("log_latest_cooling.json")) + + assert pump.heat_pump_state is HeatPump.State.COOLING + assert pump.cooling_activity is HeatPump.CoolingActivity.ACTIVE + assert pump.is_online is True + assert pump.dhw_target_temperature == 55 + # heat is removed from the water while cooling, so the output power is negative + assert pump.power_output == -2671 + assert pump.cop == pytest.approx(5.126, abs=0.001) + # every start condition is met except the demand for cooling + assert pump.cooling_start_conditions["demand"] is False + assert pump.cooling_pause_reason is HeatPump.CoolingPauseReason.WATER_TEMPERATURE_BELOW_SETPOINT + # the restart delay is counted in minutes from the last cooling cycle + assert pump.cooling_available_from.isoformat() == "2026-08-29T11:32:28+00:00" From 497583da71b3c26acb3b6d15b0bb76189a0e48fe Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Wed, 2 Sep 2026 09:22:34 +0200 Subject: [PATCH 13/19] Decode recorded API responses in the tests, and run them in CI The generated models build from a fixed list of keys, so a field the backend starts reporting is dropped without any error. Decoding a recorded response and comparing the keys back catches that, and immediately caught six indoor unit energy fields the energy model was discarding, worth about a tenth of the electricity a heat pump uses. The fixtures are real responses with the identifiers replaced, covering the heat pump list, a single heat pump, a cooling log, a standby log and the energy totals. These tests need no credentials, so unlike the build workflow they can run on pull requests from forks. They run there and on main. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01HSpCiCC4qBunYyrtXXLzkA --- .github/workflows/test.yml | 29 +++++++++++ tests/fixtures/energy_total.json | 20 ++++++++ tests/fixtures/heat_pump.json | 13 +++++ tests/fixtures/heat_pumps_list.json | 24 ++++++++++ tests/fixtures/log_latest_standby.json | 40 ++++++++++++++++ tests/test_fixtures.py | 64 +++++++++++++++++++++++-- weheat/models/total_energy_aggregate.py | 16 ++++++- 7 files changed, 199 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/test.yml create mode 100644 tests/fixtures/energy_total.json create mode 100644 tests/fixtures/heat_pump.json create mode 100644 tests/fixtures/heat_pumps_list.json create mode 100644 tests/fixtures/log_latest_standby.json diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..59f0752 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,29 @@ +name: Test + +# The build workflow needs API credentials, which pull requests from forks do not +# get. These tests decode recorded responses instead, so they need no secrets. +on: + pull_request: + push: + branches: + - main + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['3.9', '3.11', '3.13'] + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt pytest pytest-asyncio mypy + - name: Test + run: python -m pytest tests -q + - name: Type check + run: mypy -p weheat.abstractions --install-types --non-interactive diff --git a/tests/fixtures/energy_total.json b/tests/fixtures/energy_total.json new file mode 100644 index 0000000..610176d --- /dev/null +++ b/tests/fixtures/energy_total.json @@ -0,0 +1,20 @@ +{ + "totalEInHeating": 5717.358, + "totalEInStandby": 103.82725, + "totalEInDhw": 2143.2793, + "totalEInHeatingDefrost": 36.181, + "totalEInDhwDefrost": 0.045924444, + "totalEInCooling": 832.4635, + "totalEOutHeating": 27152.229, + "totalEOutDhw": 6509.1094, + "totalEOutHeatingDefrost": -799.50616, + "totalEOutDhwDefrost": -1.0773816, + "totalEOutCooling": -4438.936, + "totalEInIUStandby": 245.75871, + "totalEInIUHeating": 426.02554, + "totalEInIUDhw": 252.08315, + "totalEInIUHeatingDefrost": 22.127708, + "totalEInIUDhwDefrost": 0.038020276, + "totalEInIUCooling": 95.72314, + "heatPumpId": "00000000-0000-4000-8000-000000000000" +} diff --git a/tests/fixtures/heat_pump.json b/tests/fixtures/heat_pump.json new file mode 100644 index 0000000..d24f141 --- /dev/null +++ b/tests/fixtures/heat_pump.json @@ -0,0 +1,13 @@ +{ + "controlBoardId": "11111111-1111-4111-8111-111111111111", + "name": null, + "model": 0, + "dhwType": 1, + "boilerType": 1, + "status": 70, + "commissionedAt": "2024-07-05T16:00:00Z", + "serialNumber": "SN-0000-0000", + "partNumber": "2580-2255-2903", + "state": 3, + "id": "00000000-0000-4000-8000-000000000000" +} diff --git a/tests/fixtures/heat_pumps_list.json b/tests/fixtures/heat_pumps_list.json new file mode 100644 index 0000000..602ef79 --- /dev/null +++ b/tests/fixtures/heat_pumps_list.json @@ -0,0 +1,24 @@ +{ + "metadata": { + "totalCount": 1, + "pageSize": 10, + "currentPage": 1, + "totalPages": 1 + }, + "data": [ + { + "firmwareVersion": null, + "controlBoardId": "11111111-1111-4111-8111-111111111111", + "name": null, + "model": 0, + "dhwType": 1, + "boilerType": 1, + "status": 40, + "commissionedAt": "2024-07-05T16:00:00Z", + "serialNumber": "SN-0000-0000", + "partNumber": "2580-2255-2903", + "state": 3, + "id": "00000000-0000-4000-8000-000000000000" + } + ] +} diff --git a/tests/fixtures/log_latest_standby.json b/tests/fixtures/log_latest_standby.json new file mode 100644 index 0000000..4a5fc57 --- /dev/null +++ b/tests/fixtures/log_latest_standby.json @@ -0,0 +1,40 @@ +{ + "heatPumpId": "00000000-0000-4000-8000-000000000000", + "timestamp": "2026-09-02T07:17:57.5578988Z", + "state": 40, + "controlBridgeStatus": 4286582787, + "controlBridgeStatusDecodedWaterPump": true, + "controlBridgeStatusDecodedDhwValve": true, + "controlBridgeStatusDecodedGasBoiler": false, + "controlBridgeStatusDecodedElectricHeater": false, + "controlBridgeStatusDecodedWaterPump2": false, + "inputStatus": 29, + "t1": 53.7, + "t2": 52.8, + "tAirIn": 17.2, + "tAirOut": 16.2, + "tWaterIn": 22.3, + "tWaterOut": 22.3, + "tWaterHouseIn": 22.3, + "rpm": 0, + "cmMassPowerIn": 10, + "cmMassPowerOut": 0, + "onOffThermostatState": 0, + "tRoom": 21, + "tRoomTarget": 20, + "tThermostatSetpoint": 10, + "otBoilerFeedTemperature": null, + "otBoilerReturnTemperature": null, + "centralHeatingFlow": 2, + "dhwFlow": 2, + "hqMessageVersion": 1, + "dhwControlMethod": 1, + "dhwTargetTemperature": 55, + "coolingExponentialBackoff": 180, + "coolingStartConditions": 2043, + "coolingPauseReason": 0, + "coolingStopReason": 4, + "lastCoolingTime": "2026-09-01T18:08:44Z", + "interval": 15, + "isOnline": true +} diff --git a/tests/test_fixtures.py b/tests/test_fixtures.py index 3730b30..24119f2 100644 --- a/tests/test_fixtures.py +++ b/tests/test_fixtures.py @@ -10,7 +10,10 @@ import pytest from weheat.abstractions.heat_pump import HeatPump +from weheat.models import TotalEnergyAggregate from weheat.models.raw_heatpump_log_and_is_online_dto import RawHeatpumpLogAndIsOnlineDto +from weheat.models.read_all_heat_pump_dto_paged_response import ReadAllHeatPumpDtoPagedResponse +from weheat.models.read_heat_pump_dto import ReadHeatPumpDto FIXTURES = pathlib.Path(__file__).parent / "fixtures" @@ -20,18 +23,39 @@ def load(name: str) -> dict: return json.loads((FIXTURES / name).read_text()) -@pytest.mark.parametrize("name", [p.name for p in sorted(FIXTURES.glob("log_*.json"))]) -def test_no_log_field_is_dropped(name): - """Test the log model keeps every field the backend sent. +def dropped_fields(payload: dict, decoded: dict) -> set: + """Return the keys the model did not keep.""" + return set(payload) - set(decoded) + + +@pytest.mark.parametrize( + ("name", "model"), + [ + ("log_latest_cooling.json", RawHeatpumpLogAndIsOnlineDto), + ("log_latest_standby.json", RawHeatpumpLogAndIsOnlineDto), + ("energy_total.json", TotalEnergyAggregate), + ("heat_pump.json", ReadHeatPumpDto), + ], +) +def test_no_field_is_dropped(name, model): + """Test the model keeps every field the backend sent. from_dict picks keys one by one, so a field the backend adds is discarded without any error until it is added to the model as well. """ payload = load(name) - decoded = RawHeatpumpLogAndIsOnlineDto.from_dict(payload).to_dict() + assert not dropped_fields(payload, model.from_dict(payload).to_dict()) + + +def test_no_field_is_dropped_from_the_heat_pump_list(): + """Test the paged heat pump list keeps every field the backend sent.""" + payload = load("heat_pumps_list.json") - assert not set(payload) - set(decoded) + decoded = ReadAllHeatPumpDtoPagedResponse.from_dict(payload).to_dict() + + assert not dropped_fields(payload, decoded) + assert not dropped_fields(payload["data"][0], decoded["data"][0]) def test_cooling_log(): @@ -51,3 +75,33 @@ def test_cooling_log(): assert pump.cooling_pause_reason is HeatPump.CoolingPauseReason.WATER_TEMPERATURE_BELOW_SETPOINT # the restart delay is counted in minutes from the last cooling cycle assert pump.cooling_available_from.isoformat() == "2026-08-29T11:32:28+00:00" + + +def test_standby_log(): + """Test a log recorded after cooling was stopped for another function.""" + pump = HeatPump("https://example.invalid", "heat-pump") + pump._last_log = RawHeatpumpLogAndIsOnlineDto.from_dict(load("log_latest_standby.json")) + + assert pump.heat_pump_state is HeatPump.State.STANDBY + assert pump.cooling_activity is HeatPump.CoolingActivity.STOPPED + assert pump.cooling_stop_reason is HeatPump.CoolingStopReason.HEAT_PUMP_CONTROL + # only the outside air temperature is holding cooling off + unmet = [name for name, met in pump.cooling_start_conditions.items() if not met] + assert unmet == ["outside_air_temperature"] + # the pump is idle, so it reports no flow through either circuit + assert pump.central_heating_flow_volume == 0 + assert pump.compressor_rpm == 0 + + +def test_energy_total(): + """Test the recorded energy totals add up the way the properties report them.""" + pump = HeatPump("https://example.invalid", "heat-pump") + pump._energy_total = TotalEnergyAggregate.from_dict(load("energy_total.json")) + + assert pump.energy_in_heating == pytest.approx(5717.358) + assert pump.energy_in_defrost == pytest.approx(36.181 + 0.045924444) + # energy removed from the water is reported as a negative amount + assert pump.energy_out_cooling < 0 + assert pump.energy_total == pytest.approx( + 5717.358 + 2143.2793 + 832.4635 + 103.82725 + 36.181 + 0.045924444 + ) diff --git a/weheat/models/total_energy_aggregate.py b/weheat/models/total_energy_aggregate.py index 8154aad..6d8f4c7 100644 --- a/weheat/models/total_energy_aggregate.py +++ b/weheat/models/total_energy_aggregate.py @@ -42,7 +42,13 @@ class TotalEnergyAggregate(BaseModel): total_e_out_heating_defrost: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="totalEOutHeatingDefrost") total_e_out_dhw_defrost: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="totalEOutDhwDefrost") total_e_out_cooling: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="totalEOutCooling") - __properties: ClassVar[List[str]] = ["heatPumpId", "totalEInHeating", "totalEInStandby", "totalEInDhw", "totalEInHeatingDefrost", "totalEInDhwDefrost", "totalEInCooling", "totalEOutHeating", "totalEOutDhw", "totalEOutHeatingDefrost", "totalEOutDhwDefrost", "totalEOutCooling",] + total_ein_iu_standby: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="totalEInIUStandby") + total_ein_iu_heating: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="totalEInIUHeating") + total_ein_iu_dhw: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="totalEInIUDhw") + total_ein_iu_heating_defrost: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="totalEInIUHeatingDefrost") + total_ein_iu_dhw_defrost: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="totalEInIUDhwDefrost") + total_ein_iu_cooling: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="totalEInIUCooling") + __properties: ClassVar[List[str]] = ["heatPumpId", "totalEInHeating", "totalEInStandby", "totalEInDhw", "totalEInHeatingDefrost", "totalEInDhwDefrost", "totalEInCooling", "totalEOutHeating", "totalEOutDhw", "totalEOutHeatingDefrost", "totalEOutDhwDefrost", "totalEOutCooling", "totalEInIUStandby", "totalEInIUHeating", "totalEInIUDhw", "totalEInIUHeatingDefrost", "totalEInIUDhwDefrost", "totalEInIUCooling",] model_config = { "populate_by_name": True, @@ -104,7 +110,13 @@ def from_dict(cls, obj: Dict) -> Self: "totalEOutDhw": obj.get("totalEOutDhw"), "totalEOutHeatingDefrost": obj.get("totalEOutHeatingDefrost"), "totalEOutDhwDefrost": obj.get("totalEOutDhwDefrost"), - "totalEOutCooling": obj.get("totalEOutCooling") + "totalEOutCooling": obj.get("totalEOutCooling"), + "totalEInIUStandby": obj.get("totalEInIUStandby"), + "totalEInIUHeating": obj.get("totalEInIUHeating"), + "totalEInIUDhw": obj.get("totalEInIUDhw"), + "totalEInIUHeatingDefrost": obj.get("totalEInIUHeatingDefrost"), + "totalEInIUDhwDefrost": obj.get("totalEInIUDhwDefrost"), + "totalEInIUCooling": obj.get("totalEInIUCooling") }) return _obj From de749c59c2098904d8ccd9b32399ecd930eba4b1 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Wed, 2 Sep 2026 09:31:22 +0200 Subject: [PATCH 14/19] Record the aggregated log endpoint in the tests The aggregated log model predates the cooling and DHW fields and drops 41 of the 120 fields the backend sends. Nothing in the library reads that model, so record it as a strict xfail: it documents the gap precisely and starts failing, loudly, once the models are regenerated from the spec. The recorded buckets also show a cooling cycle being stopped: the stop reason turns to HeatPumpControl exactly when the heat pump switches to DHW. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01HSpCiCC4qBunYyrtXXLzkA --- tests/fixtures/log_aggregated_cooling.json | 122 +++++++++++++++++++++ tests/fixtures/log_aggregated_dhw.json | 122 +++++++++++++++++++++ tests/test_fixtures.py | 31 ++++++ 3 files changed, 275 insertions(+) create mode 100644 tests/fixtures/log_aggregated_cooling.json create mode 100644 tests/fixtures/log_aggregated_dhw.json diff --git a/tests/fixtures/log_aggregated_cooling.json b/tests/fixtures/log_aggregated_cooling.json new file mode 100644 index 0000000..4c49653 --- /dev/null +++ b/tests/fixtures/log_aggregated_cooling.json @@ -0,0 +1,122 @@ +{ + "timeBucket": "2026-09-01T12:26:00Z", + "interval": "Minute", + "timeCoveredInInterval": 60, + "heatPumpStateStandby": 0, + "heatPumpStateHeating": 0, + "heatPumpStateCooling": 60, + "heatPumpStateHeatingDefrost": 0, + "heatPumpStateDhwDefrost": 0, + "heatPumpStateDhw": 0, + "heatPumpStateLegionella": 0, + "heatPumpStateManualControl": 0, + "controlBridgeStatusWaterPump": 60, + "controlBridgeStatusDhwValve": 0, + "controlBridgeStatusGasBoiler": 0, + "controlBridgeStatusElectricHeater": 0, + "controlBridgeStatusWaterPump2": 60, + "t1Average": 53.4, + "t1Min": 53.4, + "t1Max": 53.4, + "t2Average": 48.1, + "t2Min": 48.1, + "t2Max": 48.1, + "tAirInAverage": 21.1, + "tAirInMin": 20.9, + "tAirInMax": 21.2, + "tAirOutAverage": 21.4, + "tAirOutMin": 20.4, + "tAirOutMax": 22.2, + "tWaterInAverage": 21.4, + "tWaterInMin": 21.4, + "tWaterInMax": 21.4, + "tWaterOutAverage": 18.8, + "tWaterOutMin": 18.3, + "tWaterOutMax": 19.1, + "tWaterHouseInAverage": 19.7, + "tWaterHouseInMin": 19.2, + "tWaterHouseInMax": 20, + "rpmAverage": 900, + "rpmMin": 900, + "rpmMax": 900, + "thermostatStateOff": 60, + "thermostatStateOn": 0, + "tRoomAverage": 22.1, + "tRoomMin": 22.1, + "tRoomMax": 22.1, + "tRoomTargetAverage": 21, + "tRoomTargetMin": 21, + "tRoomTargetMax": 21, + "tThermostatSetpointAverage": 18, + "tThermostatSetpointMin": 18, + "tThermostatSetpointMax": 18, + "otBoilerFeedTemperatureAverage": null, + "otBoilerFeedTemperatureMin": null, + "otBoilerFeedTemperatureMax": null, + "otBoilerReturnTemperatureAverage": null, + "otBoilerReturnTemperatureMin": null, + "otBoilerReturnTemperatureMax": null, + "centralHeatingFlowAverage": 1.3, + "centralHeatingFlowMin": 1.29, + "centralHeatingFlowMax": 1.32, + "centralHeatingFlowStateStandby": 0, + "centralHeatingFlowStateStandbyNoPwm": 0, + "centralHeatingFlowStateMotorBlocked": 0, + "centralHeatingFlowStatePumping": 60, + "centralHeatingFlowStatePumpingNoPwm": 0, + "centralHeatingFlowStateSuboptimalRunning": 0, + "centralHeatingFlowStateStoppedMomentarily": 0, + "centralHeatingFlowStateStoppedPermanentDamage": 0, + "dhwFlowAverage": null, + "dhwFlowMin": null, + "dhwFlowMax": null, + "dhwFlowStateStandby": 0, + "dhwFlowStateStandbyNoPwm": 60, + "dhwFlowStateMotorBlocked": 0, + "dhwFlowStatePumping": 0, + "dhwFlowStatePumpingNoPwm": 0, + "dhwFlowStateSuboptimalRunning": 0, + "dhwFlowStateStoppedMomentarily": 0, + "dhwFlowStateStoppedPermanentDamage": 0, + "hqMessageVersionMin": 1, + "hqMessageVersionMax": 1, + "dhwControlMethodFixedSetpoint": 0, + "dhwControlMethodManualSchedule": 0, + "dhwControlMethodWeheatIntelligence": 0, + "dhwTargetTemperatureAverage": 55, + "dhwTargetTemperatureMin": 55, + "dhwTargetTemperatureMax": 55, + "coolingExponentialBackoffAverage": 180, + "coolingExponentialBackoffMin": 180, + "coolingExponentialBackoffMax": 180, + "coolingStartConditionsControlMethod": 60, + "coolingStartConditionsDtc": 60, + "coolingStartConditionsOutsideAirTemperature": 60, + "coolingStartConditionsInsideTemperature": 60, + "coolingStartConditionsIndoorUnitConnected": 60, + "coolingStartConditionsWaterToAir": 60, + "coolingStartConditionsDemand": 15, + "coolingStartConditionsWaterTemperature": 60, + "coolingStartConditionsContactNotBlocked": 60, + "coolingStartConditionsExBackoff": 60, + "coolingStartConditionsHeatCoolDelay": 60, + "coolingPauseReasonNone": 60, + "coolingPauseReasonRoomTemperatureTooLow": 0, + "coolingPauseReasonOutsideTemperatureTooLow": 0, + "coolingPauseReasonOutsideColderThenWaterTemperature": 0, + "coolingPauseReasonWaterTemperatureBelowSetpoint": 0, + "coolingPauseReasonHeatPumpControl": 0, + "coolingPauseReasonWaterTemperatureBelowDewpoint": 0, + "coolingPauseReasonContactBlocked": 0, + "coolingPauseReasonDemand": 0, + "coolingStopReasonNone": 60, + "coolingStopReasonDtc": 0, + "coolingStopReasonControlMethod": 0, + "coolingStopReasonNoIndoorUnitCommunication": 0, + "coolingStopReasonHeatPumpControl": 0, + "coolingStopReasonCoolingControl": 0, + "coolingStopReasonSwitchOver": 0, + "coolingStopReasonOtCoolingDisabled": 0, + "lastCoolingTimeMin": null, + "lastCoolingTimeMax": null +} diff --git a/tests/fixtures/log_aggregated_dhw.json b/tests/fixtures/log_aggregated_dhw.json new file mode 100644 index 0000000..62debd0 --- /dev/null +++ b/tests/fixtures/log_aggregated_dhw.json @@ -0,0 +1,122 @@ +{ + "timeBucket": "2026-09-01T18:36:00Z", + "interval": "Minute", + "timeCoveredInInterval": 60, + "heatPumpStateStandby": 0, + "heatPumpStateHeating": 0, + "heatPumpStateCooling": 0, + "heatPumpStateHeatingDefrost": 0, + "heatPumpStateDhwDefrost": 0, + "heatPumpStateDhw": 60, + "heatPumpStateLegionella": 0, + "heatPumpStateManualControl": 0, + "controlBridgeStatusWaterPump": 60, + "controlBridgeStatusDhwValve": 60, + "controlBridgeStatusGasBoiler": 0, + "controlBridgeStatusElectricHeater": 0, + "controlBridgeStatusWaterPump2": 0, + "t1Average": 51.8, + "t1Min": 51.8, + "t1Max": 51.9, + "t2Average": 39.5, + "t2Min": 39, + "t2Max": 40.1, + "tAirInAverage": 17.9, + "tAirInMin": 17.7, + "tAirInMax": 18.2, + "tAirOutAverage": 15.1, + "tAirOutMin": 13.7, + "tAirOutMax": 16.9, + "tWaterInAverage": 30.4, + "tWaterInMin": 29.8, + "tWaterInMax": 31.1, + "tWaterOutAverage": 33.8, + "tWaterOutMin": 31.7, + "tWaterOutMax": 34.8, + "tWaterHouseInAverage": 19.7, + "tWaterHouseInMin": 19.2, + "tWaterHouseInMax": 20, + "rpmAverage": 2070, + "rpmMin": 1980, + "rpmMax": 2100, + "thermostatStateOff": 60, + "thermostatStateOn": 0, + "tRoomAverage": 22.1, + "tRoomMin": 22.1, + "tRoomMax": 22.1, + "tRoomTargetAverage": 21, + "tRoomTargetMin": 21, + "tRoomTargetMax": 21, + "tThermostatSetpointAverage": 18, + "tThermostatSetpointMin": 18, + "tThermostatSetpointMax": 18, + "otBoilerFeedTemperatureAverage": null, + "otBoilerFeedTemperatureMin": null, + "otBoilerFeedTemperatureMax": null, + "otBoilerReturnTemperatureAverage": null, + "otBoilerReturnTemperatureMin": null, + "otBoilerReturnTemperatureMax": null, + "centralHeatingFlowAverage": null, + "centralHeatingFlowMin": null, + "centralHeatingFlowMax": null, + "centralHeatingFlowStateStandby": 60, + "centralHeatingFlowStateStandbyNoPwm": 0, + "centralHeatingFlowStateMotorBlocked": 0, + "centralHeatingFlowStatePumping": 0, + "centralHeatingFlowStatePumpingNoPwm": 0, + "centralHeatingFlowStateSuboptimalRunning": 0, + "centralHeatingFlowStateStoppedMomentarily": 0, + "centralHeatingFlowStateStoppedPermanentDamage": 0, + "dhwFlowAverage": 1.14, + "dhwFlowMin": 1.14, + "dhwFlowMax": 1.14, + "dhwFlowStateStandby": 0, + "dhwFlowStateStandbyNoPwm": 0, + "dhwFlowStateMotorBlocked": 0, + "dhwFlowStatePumping": 60, + "dhwFlowStatePumpingNoPwm": 0, + "dhwFlowStateSuboptimalRunning": 0, + "dhwFlowStateStoppedMomentarily": 0, + "dhwFlowStateStoppedPermanentDamage": 0, + "hqMessageVersionMin": 1, + "hqMessageVersionMax": 1, + "dhwControlMethodFixedSetpoint": 0, + "dhwControlMethodManualSchedule": 0, + "dhwControlMethodWeheatIntelligence": 0, + "dhwTargetTemperatureAverage": 55, + "dhwTargetTemperatureMin": 55, + "dhwTargetTemperatureMax": 55, + "coolingExponentialBackoffAverage": 180, + "coolingExponentialBackoffMin": 180, + "coolingExponentialBackoffMax": 180, + "coolingStartConditionsControlMethod": 60, + "coolingStartConditionsDtc": 60, + "coolingStartConditionsOutsideAirTemperature": 15, + "coolingStartConditionsInsideTemperature": 60, + "coolingStartConditionsIndoorUnitConnected": 60, + "coolingStartConditionsWaterToAir": 60, + "coolingStartConditionsDemand": 15, + "coolingStartConditionsWaterTemperature": 60, + "coolingStartConditionsContactNotBlocked": 60, + "coolingStartConditionsExBackoff": 0, + "coolingStartConditionsHeatCoolDelay": 60, + "coolingPauseReasonNone": 60, + "coolingPauseReasonRoomTemperatureTooLow": 0, + "coolingPauseReasonOutsideTemperatureTooLow": 0, + "coolingPauseReasonOutsideColderThenWaterTemperature": 0, + "coolingPauseReasonWaterTemperatureBelowSetpoint": 0, + "coolingPauseReasonHeatPumpControl": 0, + "coolingPauseReasonWaterTemperatureBelowDewpoint": 0, + "coolingPauseReasonContactBlocked": 0, + "coolingPauseReasonDemand": 0, + "coolingStopReasonNone": 0, + "coolingStopReasonDtc": 0, + "coolingStopReasonControlMethod": 0, + "coolingStopReasonNoIndoorUnitCommunication": 0, + "coolingStopReasonHeatPumpControl": 60, + "coolingStopReasonCoolingControl": 0, + "coolingStopReasonSwitchOver": 0, + "coolingStopReasonOtCoolingDisabled": 0, + "lastCoolingTimeMin": "2026-09-01T18:08:44Z", + "lastCoolingTimeMax": "2026-09-01T18:08:44Z" +} diff --git a/tests/test_fixtures.py b/tests/test_fixtures.py index 24119f2..af0c8f6 100644 --- a/tests/test_fixtures.py +++ b/tests/test_fixtures.py @@ -11,6 +11,7 @@ from weheat.abstractions.heat_pump import HeatPump from weheat.models import TotalEnergyAggregate +from weheat.models.heat_pump_log_view_dto import HeatPumpLogViewDto from weheat.models.raw_heatpump_log_and_is_online_dto import RawHeatpumpLogAndIsOnlineDto from weheat.models.read_all_heat_pump_dto_paged_response import ReadAllHeatPumpDtoPagedResponse from weheat.models.read_heat_pump_dto import ReadHeatPumpDto @@ -105,3 +106,33 @@ def test_energy_total(): assert pump.energy_total == pytest.approx( 5717.358 + 2143.2793 + 832.4635 + 103.82725 + 36.181 + 0.045924444 ) + + +@pytest.mark.parametrize( + "name", ["log_aggregated_cooling.json", "log_aggregated_dhw.json"] +) +@pytest.mark.xfail( + strict=True, + reason="the aggregated log model predates the cooling and DHW fields, so it " + "drops all of them; regenerating the models from the spec fixes this", +) +def test_no_field_is_dropped_from_the_aggregated_log(name): + """Test the aggregated log model keeps every field the backend sent.""" + payload = load(name) + + assert not dropped_fields(payload, HeatPumpLogViewDto.from_dict(payload).to_dict()) + + +def test_cooling_is_stopped_when_dhw_takes_over(): + """Test the recorded buckets show what stops a cooling cycle. + + The stop reason turns to HeatPumpControl exactly when the heat pump switches + to DHW, which is what that reason means: another function took priority. + """ + cooling = load("log_aggregated_cooling.json") + dhw = load("log_aggregated_dhw.json") + + assert cooling["heatPumpStateCooling"] == 60 + assert cooling["coolingStopReasonNone"] == 60 + assert dhw["heatPumpStateDhw"] == 60 + assert dhw["coolingStopReasonHeatPumpControl"] == 60 From 63090b39920e3eff5ee399de27638e7f5c59eb21 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Wed, 2 Sep 2026 09:33:47 +0200 Subject: [PATCH 15/19] Record a log from firmware that predates the cooling fields Half a year old, so the cooling and DHW fields are present but null, along with hqMessageVersion. That pins down two things: the backend sends the same keys either way, so a consumer cannot tell an older heat pump apart by shape alone, and a heat pump reporting nulls decodes to no cooling at all, which is what the integration relies on to leave the cooling entities off such a heat pump. The 41 null fields are exactly the 41 the aggregated model drops, which dates when the model was generated. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01HSpCiCC4qBunYyrtXXLzkA --- .../log_aggregated_heating_old_firmware.json | 122 ++++++++++++++++++ tests/test_fixtures.py | 39 +++++- 2 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/log_aggregated_heating_old_firmware.json diff --git a/tests/fixtures/log_aggregated_heating_old_firmware.json b/tests/fixtures/log_aggregated_heating_old_firmware.json new file mode 100644 index 0000000..5a630d6 --- /dev/null +++ b/tests/fixtures/log_aggregated_heating_old_firmware.json @@ -0,0 +1,122 @@ +{ + "timeBucket": "2026-01-01T18:30:00Z", + "interval": "Minute", + "timeCoveredInInterval": 60, + "heatPumpStateStandby": 0, + "heatPumpStateHeating": 60, + "heatPumpStateCooling": 0, + "heatPumpStateHeatingDefrost": 0, + "heatPumpStateDhwDefrost": 0, + "heatPumpStateDhw": 0, + "heatPumpStateLegionella": 0, + "heatPumpStateManualControl": 0, + "controlBridgeStatusWaterPump": 60, + "controlBridgeStatusDhwValve": 60, + "controlBridgeStatusGasBoiler": 0, + "controlBridgeStatusElectricHeater": 0, + "controlBridgeStatusWaterPump2": 60, + "t1Average": 63.5, + "t1Min": 63.5, + "t1Max": 63.5, + "t2Average": 25, + "t2Min": 24.9, + "t2Max": 25, + "tAirInAverage": 4.4, + "tAirInMin": 4.3, + "tAirInMax": 4.4, + "tAirOutAverage": 0.9, + "tAirOutMin": 0.8, + "tAirOutMax": 0.9, + "tWaterInAverage": 24.5, + "tWaterInMin": 24.5, + "tWaterInMax": 24.5, + "tWaterOutAverage": 27.1, + "tWaterOutMin": 27.1, + "tWaterOutMax": 27.1, + "tWaterHouseInAverage": 27.5, + "tWaterHouseInMin": 27.5, + "tWaterHouseInMax": 27.5, + "rpmAverage": 1620, + "rpmMin": 1620, + "rpmMax": 1620, + "thermostatStateOff": 60, + "thermostatStateOn": 0, + "tRoomAverage": 20.7, + "tRoomMin": 20.7, + "tRoomMax": 20.7, + "tRoomTargetAverage": 21, + "tRoomTargetMin": 21, + "tRoomTargetMax": 21, + "tThermostatSetpointAverage": 27.5, + "tThermostatSetpointMin": 27.4, + "tThermostatSetpointMax": 27.5, + "otBoilerFeedTemperatureAverage": null, + "otBoilerFeedTemperatureMin": null, + "otBoilerFeedTemperatureMax": null, + "otBoilerReturnTemperatureAverage": null, + "otBoilerReturnTemperatureMin": null, + "otBoilerReturnTemperatureMax": null, + "centralHeatingFlowAverage": 1.3, + "centralHeatingFlowMin": 1.29, + "centralHeatingFlowMax": 1.32, + "centralHeatingFlowStateStandby": 0, + "centralHeatingFlowStateStandbyNoPwm": 0, + "centralHeatingFlowStateMotorBlocked": 0, + "centralHeatingFlowStatePumping": 60, + "centralHeatingFlowStatePumpingNoPwm": 0, + "centralHeatingFlowStateSuboptimalRunning": 0, + "centralHeatingFlowStateStoppedMomentarily": 0, + "centralHeatingFlowStateStoppedPermanentDamage": 0, + "dhwFlowAverage": null, + "dhwFlowMin": null, + "dhwFlowMax": null, + "dhwFlowStateStandby": 60, + "dhwFlowStateStandbyNoPwm": 0, + "dhwFlowStateMotorBlocked": 0, + "dhwFlowStatePumping": 0, + "dhwFlowStatePumpingNoPwm": 0, + "dhwFlowStateSuboptimalRunning": 0, + "dhwFlowStateStoppedMomentarily": 0, + "dhwFlowStateStoppedPermanentDamage": 0, + "hqMessageVersionMin": null, + "hqMessageVersionMax": null, + "dhwControlMethodFixedSetpoint": null, + "dhwControlMethodManualSchedule": null, + "dhwControlMethodWeheatIntelligence": null, + "dhwTargetTemperatureAverage": null, + "dhwTargetTemperatureMin": null, + "dhwTargetTemperatureMax": null, + "coolingExponentialBackoffAverage": null, + "coolingExponentialBackoffMin": null, + "coolingExponentialBackoffMax": null, + "coolingStartConditionsControlMethod": null, + "coolingStartConditionsDtc": null, + "coolingStartConditionsOutsideAirTemperature": null, + "coolingStartConditionsInsideTemperature": null, + "coolingStartConditionsIndoorUnitConnected": null, + "coolingStartConditionsWaterToAir": null, + "coolingStartConditionsDemand": null, + "coolingStartConditionsWaterTemperature": null, + "coolingStartConditionsContactNotBlocked": null, + "coolingStartConditionsExBackoff": null, + "coolingStartConditionsHeatCoolDelay": null, + "coolingPauseReasonNone": null, + "coolingPauseReasonRoomTemperatureTooLow": null, + "coolingPauseReasonOutsideTemperatureTooLow": null, + "coolingPauseReasonOutsideColderThenWaterTemperature": null, + "coolingPauseReasonWaterTemperatureBelowSetpoint": null, + "coolingPauseReasonHeatPumpControl": null, + "coolingPauseReasonWaterTemperatureBelowDewpoint": null, + "coolingPauseReasonContactBlocked": null, + "coolingPauseReasonDemand": null, + "coolingStopReasonNone": null, + "coolingStopReasonDtc": null, + "coolingStopReasonControlMethod": null, + "coolingStopReasonNoIndoorUnitCommunication": null, + "coolingStopReasonHeatPumpControl": null, + "coolingStopReasonCoolingControl": null, + "coolingStopReasonSwitchOver": null, + "coolingStopReasonOtCoolingDisabled": null, + "lastCoolingTimeMin": null, + "lastCoolingTimeMax": null +} diff --git a/tests/test_fixtures.py b/tests/test_fixtures.py index af0c8f6..1569d8e 100644 --- a/tests/test_fixtures.py +++ b/tests/test_fixtures.py @@ -109,7 +109,12 @@ def test_energy_total(): @pytest.mark.parametrize( - "name", ["log_aggregated_cooling.json", "log_aggregated_dhw.json"] + "name", + [ + "log_aggregated_cooling.json", + "log_aggregated_dhw.json", + "log_aggregated_heating_old_firmware.json", + ], ) @pytest.mark.xfail( strict=True, @@ -136,3 +141,35 @@ def test_cooling_is_stopped_when_dhw_takes_over(): assert cooling["coolingStopReasonNone"] == 60 assert dhw["heatPumpStateDhw"] == 60 assert dhw["coolingStopReasonHeatPumpControl"] == 60 + + +def test_older_firmware_reports_the_cooling_fields_as_null(): + """Test the backend sends the cooling fields even for firmware that predates them. + + The fields are present and null rather than missing, which is what lets a + consumer tell "this heat pump does not report cooling" from "this response + is from before cooling existed": both look the same, and both mean no cooling. + """ + payload = load("log_aggregated_heating_old_firmware.json") + current = load("log_aggregated_cooling.json") + + assert set(payload) == set(current) + assert payload["hqMessageVersionMin"] is None + assert current["hqMessageVersionMin"] == 1 + assert all( + payload[key] is None for key in payload if key.startswith("coolingStartConditions") + ) + + +def test_a_heat_pump_without_the_cooling_fields_reports_no_cooling(): + """Test a log from firmware without cooling decodes to no cooling at all.""" + pump = HeatPump("https://example.invalid", "heat-pump") + pump._last_log = RawHeatpumpLogAndIsOnlineDto.model_validate( + {"heat_pump_id": "heat-pump", "timestamp": "2026-01-01T18:30:00+00:00", + "interval": 15, "state": 70} + ) + + assert pump.heat_pump_state is HeatPump.State.HEATING + assert pump.cooling_activity is None + assert pump.cooling_start_conditions is None + assert pump.cooling_available_from is None From cf3f80cdc608f02ed31c8b176344a25b6bf0efbe Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Wed, 2 Sep 2026 09:47:46 +0200 Subject: [PATCH 16/19] Report the electrical energy the indoor unit uses The backend meters the indoor unit separately, and energy_total only covers the outdoor unit, so around a tenth of the electricity a heat pump uses was not reported at all. Add it as its own property rather than folding it into energy_total, which consumers track as a rising total. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01HSpCiCC4qBunYyrtXXLzkA --- tests/test_fixtures.py | 5 +++++ weheat/abstractions/heat_pump.py | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/test_fixtures.py b/tests/test_fixtures.py index 1569d8e..730bc4b 100644 --- a/tests/test_fixtures.py +++ b/tests/test_fixtures.py @@ -106,6 +106,11 @@ def test_energy_total(): assert pump.energy_total == pytest.approx( 5717.358 + 2143.2793 + 832.4635 + 103.82725 + 36.181 + 0.045924444 ) + # the indoor unit is metered separately, and is not part of that total + assert pump.energy_in_indoor_unit == pytest.approx( + 426.02554 + 252.08315 + 95.72314 + 245.75871 + 22.127708 + 0.038020276 + ) + assert pump.energy_in_indoor_unit < pump.energy_total @pytest.mark.parametrize( diff --git a/weheat/abstractions/heat_pump.py b/weheat/abstractions/heat_pump.py index de118e8..f6c0e31 100644 --- a/weheat/abstractions/heat_pump.py +++ b/weheat/abstractions/heat_pump.py @@ -627,7 +627,11 @@ def energy_out_cooling(self) -> Union[float, None]: @property def energy_total(self) -> Union[float, None]: - """The total used (electrical) energy in kWh.""" + """The total used (electrical) energy of the outdoor unit in kWh. + + This does not include the indoor unit, which the heat pump meters + separately and reports through energy_in_indoor_unit. + """ if self._energy_total is None: return None return float( @@ -636,6 +640,18 @@ def energy_total(self) -> Union[float, None]: self._energy_total.total_ein_heating_defrost + self._energy_total.total_ein_dhw_defrost ) + @property + def energy_in_indoor_unit(self) -> Union[float, None]: + """The total used (electrical) energy of the indoor unit in kWh.""" + if self._energy_total is None: + return None + return float( + self._energy_total.total_ein_iu_heating + self._energy_total.total_ein_iu_dhw + + self._energy_total.total_ein_iu_cooling + self._energy_total.total_ein_iu_standby + + self._energy_total.total_ein_iu_heating_defrost + + self._energy_total.total_ein_iu_dhw_defrost + ) + @property def energy_output(self) -> Union[float, None]: """The total useful generated energy for the house in kWh.""" From ada45109238cb7e83ef6a5009f7412979264c1d0 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Wed, 2 Sep 2026 09:53:05 +0200 Subject: [PATCH 17/19] Only claim the Python versions the package can import on Four annotations use X | None, which is only valid at runtime from 3.10, one of them in generated code and so back on the next regeneration. The package declared 3.7, so pip would install it on 3.9 and it would fail on import. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01HSpCiCC4qBunYyrtXXLzkA --- .github/workflows/test.yml | 2 +- pyproject.toml | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 59f0752..0c6b19b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.9', '3.11', '3.13'] + python-version: ['3.10', '3.12', '3.13'] steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 diff --git a/pyproject.toml b/pyproject.toml index 7d7e940..92f0ada 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ keywords = ["OpenAPI", "OpenAPI-Generator", "Weheat Backend"] include = ["weheat/py.typed"] [tool.poetry.dependencies] -python = "^3.7" +python = "^3.10" urllib3 = ">= 1.25.3" python-dateutil = ">=2.8.2" diff --git a/setup.py b/setup.py index e2f5a96..56d941c 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ # http://pypi.python.org/pypi/setuptools NAME = "weheat" VERSION = "2026.9.2" -PYTHON_REQUIRES = ">=3.7" +PYTHON_REQUIRES = ">=3.10" REQUIRES = [ "urllib3 >= 1.25.3, < 3.0.0", "python-dateutil", From 4827277a07245a32f68fcdcaa1da66a775d8b860 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Wed, 2 Sep 2026 10:10:31 +0200 Subject: [PATCH 18/19] Report the raw code behind each decoded value The decoded properties return None both for a code this version cannot name and for a heat pump that does not report the field at all. Consumers need to tell those apart, and were left reading the raw log to do it, which puts the vendor field names in each consumer. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01HSpCiCC4qBunYyrtXXLzkA --- tests/test_heat_pump.py | 24 ++++++++++++++++++++++++ weheat/abstractions/heat_pump.py | 20 ++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/tests/test_heat_pump.py b/tests/test_heat_pump.py index 5bbb723..c5b4f3c 100644 --- a/tests/test_heat_pump.py +++ b/tests/test_heat_pump.py @@ -140,3 +140,27 @@ def test_unknown_codes_decode_to_nothing(code): assert pump.cooling_pause_reason is None assert pump.cooling_stop_reason is None + + +@pytest.mark.parametrize( + ("code", "expected_name"), + [(4, HeatPump.CoolingPauseReason.WATER_TEMPERATURE_BELOW_SETPOINT), (99, None)], +) +def test_a_code_is_reported_even_when_it_cannot_be_named(code, expected_name): + """Test the code is reported whether or not this version can name it. + + That is what lets a consumer tell a heat pump reporting an unknown value + apart from one not reporting the value at all. + """ + pump = heat_pump(cooling_pause_reason=code) + + assert pump.cooling_pause_reason_code == code + assert pump.cooling_pause_reason is expected_name + + +def test_no_code_is_reported_when_the_field_is_absent(): + """Test a heat pump that does not report the field reports no code either.""" + pump = heat_pump(state=40) + + assert pump.cooling_pause_reason_code is None + assert pump.heat_pump_state_code == 40 diff --git a/weheat/abstractions/heat_pump.py b/weheat/abstractions/heat_pump.py index f6c0e31..910f3f2 100644 --- a/weheat/abstractions/heat_pump.py +++ b/weheat/abstractions/heat_pump.py @@ -208,6 +208,26 @@ def __str__(self) -> str: def __repr__(self) -> str: return self.__str__() + @property + def heat_pump_state_code(self) -> Union[int, None]: + """The raw state the heat pump reports, named by heat_pump_state.""" + return self._if_available("state") + + @property + def current_control_method_code(self) -> Union[int, None]: + """The raw control method the heat pump reports, named by current_control_method.""" + return self._if_available("current_control_method") + + @property + def cooling_pause_reason_code(self) -> Union[int, None]: + """The raw pause reason the heat pump reports, named by cooling_pause_reason.""" + return self._if_available("cooling_pause_reason") + + @property + def cooling_stop_reason_code(self) -> Union[int, None]: + """The raw stop reason the heat pump reports, named by cooling_stop_reason.""" + return self._if_available("cooling_stop_reason") + @property def raw_content(self) -> Optional[dict]: raw = {} From c1c6eaec48b95ae35a8553cd06ee53f9c8542b3f Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Wed, 2 Sep 2026 10:36:07 +0200 Subject: [PATCH 19/19] Decode the DHW control method The heat pump reports the firmware enum in its log, which numbers its values differently from the enum of the same name the portal uses for the installation setting: the log reports 1 for a fixed setpoint where the portal setting uses 0. Decoding through the portal enum would have named the method wrongly rather than leaving it unknown. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01HSpCiCC4qBunYyrtXXLzkA --- tests/test_fixtures.py | 1 + tests/test_heat_pump.py | 19 +++++++++++++++++++ weheat/abstractions/heat_pump.py | 30 ++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/tests/test_fixtures.py b/tests/test_fixtures.py index 730bc4b..d1039d8 100644 --- a/tests/test_fixtures.py +++ b/tests/test_fixtures.py @@ -68,6 +68,7 @@ def test_cooling_log(): assert pump.cooling_activity is HeatPump.CoolingActivity.ACTIVE assert pump.is_online is True assert pump.dhw_target_temperature == 55 + assert pump.dhw_control_method is HeatPump.DhwControlMethod.FIXED # heat is removed from the water while cooling, so the output power is negative assert pump.power_output == -2671 assert pump.cop == pytest.approx(5.126, abs=0.001) diff --git a/tests/test_heat_pump.py b/tests/test_heat_pump.py index c5b4f3c..8f15677 100644 --- a/tests/test_heat_pump.py +++ b/tests/test_heat_pump.py @@ -164,3 +164,22 @@ def test_no_code_is_reported_when_the_field_is_absent(): assert pump.cooling_pause_reason_code is None assert pump.heat_pump_state_code == 40 + + +@pytest.mark.parametrize( + ("code", "expected"), + [ + (0, HeatPump.DhwControlMethod.NONE), + (1, HeatPump.DhwControlMethod.FIXED), + (2, HeatPump.DhwControlMethod.SCHEDULE), + (3, HeatPump.DhwControlMethod.WEHEAT_INTELLIGENCE), + (4, HeatPump.DhwControlMethod.BOOST), + (99, None), + ], +) +def test_dhw_control_method(code, expected): + """Test the control method the DHW vessel runs on.""" + pump = heat_pump(dhw_control_method=code) + + assert pump.dhw_control_method is expected + assert pump.dhw_control_method_code == code diff --git a/weheat/abstractions/heat_pump.py b/weheat/abstractions/heat_pump.py index 910f3f2..0a4ef60 100644 --- a/weheat/abstractions/heat_pump.py +++ b/weheat/abstractions/heat_pump.py @@ -31,6 +31,19 @@ class State(Enum): MANUAL_CONTROL = auto() UPDATING = auto() + class DhwControlMethod(Enum): + """The control method the heat pump reports for the DHW vessel. + + The portal has an enum of the same name for the installation setting, + which numbers its values differently. This is the one the log uses. + """ + + NONE = 0 + FIXED = 1 + SCHEDULE = 2 + WEHEAT_INTELLIGENCE = 3 + BOOST = 4 + class CoolingState(Enum): IDLE = 130 STARTING = 131 @@ -218,6 +231,11 @@ def current_control_method_code(self) -> Union[int, None]: """The raw control method the heat pump reports, named by current_control_method.""" return self._if_available("current_control_method") + @property + def dhw_control_method_code(self) -> Union[int, None]: + """The raw DHW control method, named by dhw_control_method.""" + return self._if_available("dhw_control_method") + @property def cooling_pause_reason_code(self) -> Union[int, None]: """The raw pause reason the heat pump reports, named by cooling_pause_reason.""" @@ -422,6 +440,18 @@ def current_control_method(self) -> Union["HeatPump.ControlMethod", None]: # The backend may report methods this version does not know about yet. return None + @property + def dhw_control_method(self) -> Union["HeatPump.DhwControlMethod", None]: + """The control method the DHW vessel is running on.""" + value = self.dhw_control_method_code + if value is None: + return None + try: + return self.DhwControlMethod(value) + except ValueError: + # The backend may report methods this version does not know about yet. + return None + @property def cooling_state(self) -> Union["HeatPump.CoolingState", None]: """The cooling sub state, only set while the heat pump is in a cooling state."""