Repository navigation
Add cooling log fields, fix COP sign and silent energy failures - #59
Conversation
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) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0196E9qDnocL42PxpgJrLc87
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) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0196E9qDnocL42PxpgJrLc87
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) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0196E9qDnocL42PxpgJrLc87
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) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0196E9qDnocL42PxpgJrLc87
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) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0196E9qDnocL42PxpgJrLc87
jesperraemaekers
left a comment
There was a problem hiding this comment.
Also because you have not explicitly state it, or AI hasn't stated it, was it tested?
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) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0196E9qDnocL42PxpgJrLc87
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) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0196E9qDnocL42PxpgJrLc87
|
Related HA pull request: home-assistant/core#180904 |
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) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0196E9qDnocL42PxpgJrLc87
|
Good busy! |
Co-authored-by: jesperraemaekers <146726232+jesperraemaekers@users.noreply.github.com>
|
Can confirm the sign issue from my own logging, if that helps with the "was it tested" question. I've been polling a Blackbird P80 every 15 to 60 seconds since 2 August. Taking only the samples where the pump was in a cooling state with the compressor actually running: 24,378 samples, of which 24,319 have a negative So negative is the rule in cooling rather than an exception, and a COP taken straight off that field over a cooling run comes out the wrong way round. Happy to check anything else against that data if it's useful. |
jesperraemaekers
left a comment
There was a problem hiding this comment.
Also if you want you can bump the version number so i'll release it when this is merged
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) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0196E9qDnocL42PxpgJrLc87
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0196E9qDnocL42PxpgJrLc87
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) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0196E9qDnocL42PxpgJrLc87
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) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HSpCiCC4qBunYyrtXXLzkA
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) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HSpCiCC4qBunYyrtXXLzkA
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) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HSpCiCC4qBunYyrtXXLzkA
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) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HSpCiCC4qBunYyrtXXLzkA
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) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HSpCiCC4qBunYyrtXXLzkA
I added some fixture tests to the pipeline, because I cannot run it against the live API. I encountered issues with Python 3.9 in the matrix, so I had to bump to 3.10 (because of the generated code: I also added the indoor electricity used, which I think is not added to the total. I guess we could keep it like that and I'll add indoor electricity to HA as a new sensor.
I bumped the version to 2026.9.2 I hope I have the logic correct now. I also saw the DhWControlMethod but I think there is some more logic behind that. |
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) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HSpCiCC4qBunYyrtXXLzkA
In case you want to add it, these are the states: |
|
Let me know if you want to merge it like this or also want to add 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) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HSpCiCC4qBunYyrtXXLzkA
|
Its published |
|
Thanks! I submitted PR to updated in HA: home-assistant/core#181065 |
|
Based on feedback I changed the COP a bit, to only flip the sign to positive for cooling, and keep the other negative values: #60 |
|
@jesperraemaekers is it possible to detect wether cooling is Enabled or not? So we can conditionally add the cooling fields or not? I tried disabling cooling, but it keeps the API settings. I can't test with non-cooling devices (or you might have fixtures for that?) isCoolingEnabled is in the settings endpoint we cannot reach. |
You should be able to reach that setting via api/v1/installations/uuid/settings |
Those are not listed in https://api.weheat.nl/third_party/api/debugger Also, the energy fields are the same for everyone right? Even though no cooling / indoor unit is used, they still have the fields right? |
ah i forgot about that. If it's not in there then adding them does not make sense. The fields should be all the same, just some values will not change from 0. |
|
Quick question on three fields in the spec that never reach an owner token on my Blackbird P80: coolingStatus, fan and fanPower. /logs/latest returns 39 fields and none of these is among them. Is that intentional, or does it depend on account type or firmware? |








Adds the eight fields the backend already returns on the latest-log endpoint but
from_dictdropped, exposes them as properties, and fixes two bugs found on the way.Fixes
copwas negative whenever the pump was cooling or defrosting, sincecmMassPowerOutis negative in those states — 521 W in / −2671 W out reported−5.1 instead of 5.1.
async_get_energyswallowed every exception, so callers couldn't tell a failedfetch from a pump with no energy data. It now re-raises, like
async_get_logs.test_hp_logassertedpower_output >= 0unconditionally, which fails as soonas a test pump happens to be cooling.
New properties
is_online,dhw_target_temperature,last_cooling_timecooling_pause_reason,cooling_stop_reason,current_control_method— decodedthrough enums rather than raw codes
cooling_start_conditions— decodes thecoolingStartConditionsbitfield into anamed flag per condition
cooling_backoffandcooling_available_fromUnknown codes decode to
Nonerather than raising, so a backend that grows a newvalue won't break existing callers.
Worth a second look before merging
CoolingStopReasonvalues 1–7 are inferred from the order the portal liststhem in.
None = 0is confirmed by live logs; the rest aren't.CoolingPauseReason,ControlMethodand the condition bit masks are verbatim from the portal.replaced by a regeneration once the OpenAPI spec carries them.
Notes
async_get_energynow raises where it previously returned quietly — a behaviourchange for any existing caller.