Skip to content

Add cooling log fields, fix COP sign and silent energy failures - #59

Merged
jesperraemaekers merged 19 commits into
wefabricate:mainfrom
barryvdh:feat-cooling-fields
Sep 2, 2026
Merged

jesperraemaekers merged 19 commits into
wefabricate:mainfrom
barryvdh:feat-cooling-fields

Conversation

@barryvdh

Copy link
Copy Markdown
Contributor

Adds the eight fields the backend already returns on the latest-log endpoint but
from_dict dropped, exposes them as properties, and fixes two bugs found on the way.

Fixes

  • cop was negative whenever the pump was cooling or defrosting, since
    cmMassPowerOut is negative in those states — 521 W in / −2671 W out reported
    −5.1 instead of 5.1.
  • async_get_energy swallowed every exception, so callers couldn't tell a failed
    fetch from a pump with no energy data. It now re-raises, like async_get_logs.
  • test_hp_log asserted power_output >= 0 unconditionally, which fails as soon
    as a test pump happens to be cooling.

New properties

  • is_online, dhw_target_temperature, last_cooling_time
  • cooling_pause_reason, cooling_stop_reason, current_control_method — decoded
    through enums rather than raw codes
  • cooling_start_conditions — decodes the coolingStartConditions bitfield into a
    named flag per condition
  • cooling_backoff and cooling_available_from

Unknown codes decode to None rather than raising, so a backend that grows a new
value won't break existing callers.

Worth a second look before merging

  • CoolingStopReason values 1–7 are inferred from the order the portal lists
    them in. None = 0 is confirmed by live logs; the rest aren't. CoolingPauseReason,
    ControlMethod and the condition bit masks are verbatim from the portal.
  • The model fields were added by hand to match generator output — they should be
    replaced by a regeneration once the OpenAPI spec carries them.

Notes

  • async_get_energy now raises where it previously returned quietly — a behaviour
    change for any existing caller.
  • No version bump included; left for whoever cuts the release.

barryvdh and others added 5 commits August 29, 2026 15:54
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 jesperraemaekers left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also because you have not explicitly state it, or AI hasn't stated it, was it tested?

Comment thread weheat/abstractions/heat_pump.py Resolved
Comment thread weheat/abstractions/heat_pump.py Resolved
Comment thread weheat/abstractions/heat_pump.py Resolved
barryvdh and others added 2 commits August 31, 2026 12:21
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
@barryvdh

Copy link
Copy Markdown
Contributor Author

Also because you have not explicitly state it, or AI hasn't stated it, was it tested?

I'm running this in HA now:

Air outlet:
Screenshot 2026-08-31 at 12 29 14@2x

Cooling diagnostics:
Screenshot 2026-08-31 at 12 46 25@2x
Screenshot 2026-08-31 at 12 49 28@2x

Similar to portal
Screenshot 2026-08-31 at 12 49 39@2x

I'd have to check the timestamps when cooling starts again.

@barryvdh

Copy link
Copy Markdown
Contributor Author

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
@Tableflipper9001

Copy link
Copy Markdown
Contributor

Good busy!

Co-authored-by: jesperraemaekers <146726232+jesperraemaekers@users.noreply.github.com>
@frrankweber-rgb

Copy link
Copy Markdown

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 cmMassPowerOut, between -2,047 and -7,778 W. The 59 that don't are all around mode changes, where the state field seems to lag a moment behind.

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 jesperraemaekers left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also if you want you can bump the version number so i'll release it when this is merged

Comment thread weheat/abstractions/heat_pump.py Resolved
barryvdh and others added 8 commits September 2, 2026 09:39
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
@barryvdh

barryvdh commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Also because you have not explicitly state it, or AI hasn't stated it, was it tested?

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:

weheat/configuration.py:205: in Configuration
      def client_session(self) -> aiohttp.ClientSession|None:
  E   TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'

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.

Also if you want you can bump the version number so i'll release it when this is merged

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.

@barryvdh

barryvdh commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Tested this branch in HA:

Screenshot 2026-09-02 at 10 00 53

✅ Cooling state correct
✅ COP positive
✅ Air outlet temp available

Screenshot 2026-09-02 at 10 03 17

✅ Indoor electricity used available (Note: NOT included in total energy used)

Screenshot 2026-09-02 at 10 02 13

✅ Diagnostics look okay

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
@jesperraemaekers

Copy link
Copy Markdown
Collaborator

I hope I have the logic correct now. I also saw the DhWControlMethod but I think there is some more logic behind that.

In case you want to add it, these are the states:
DHW_CONTROL_METHOD_NONE = 0, DHW_CONTROL_METHOD_FIXED = 1, DHW_CONTROL_METHOD_SCHEDULE = 2, DHW_CONTROL_METHOD_WHI = 3, DHW_CONTROL_METHOD_BOOST = 4,

@jesperraemaekers

Copy link
Copy Markdown
Collaborator

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
@barryvdh

barryvdh commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Let me know if you want to merge it like this or also want to add dhw control method

Add DHW control:
Screenshot 2026-09-02 at 10 51 51@2x

@jesperraemaekers
jesperraemaekers merged commit 1588688 into wefabricate:main Sep 2, 2026
3 checks passed
@jesperraemaekers

Copy link
Copy Markdown
Collaborator

Its published

@barryvdh

barryvdh commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks! I submitted PR to updated in HA: home-assistant/core#181065

@barryvdh

barryvdh commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

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

@barryvdh

barryvdh commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

@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.

@jesperraemaekers

Copy link
Copy Markdown
Collaborator

@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
where you'll find cooling control method and cooling enabled

@barryvdh

barryvdh commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

@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 where you'll find cooling control method and cooling enabled

Those are not listed in https://api.weheat.nl/third_party/api/debugger
Are those okay for third party, and should I add them?

Also, the energy fields are the same for everyone right? Even though no cooling / indoor unit is used, they still have the fields right?

@jesperraemaekers

Copy link
Copy Markdown
Collaborator

@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 where you'll find cooling control method and cooling enabled

Those are not listed in https://api.weheat.nl/third_party/api/debugger Are those okay for third party, and should I add them?

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.

@frrankweber-rgb

Copy link
Copy Markdown

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants