Skip to content

Fix heating mode keyerror - #166

Merged
KJonline merged 6 commits into
devfrom
fix-heating-mode-keyerror
Oct 15, 2026
Merged

KJonline merged 6 commits into
devfrom
fix-heating-mode-keyerror

Conversation

@KJonline

Copy link
Copy Markdown
Contributor

No description provided.

KJonline and others added 6 commits October 10, 2026 11:31
Replace try/except KeyError blocks in heating/hotwater get_mode with early
returns when state.mode is missing. Add _keep_missing_state to PollingMixin
that carries over dropped state keys from the previous poll for up to
MAX_STALE_STATE_POLLS (5) consecutive incomplete responses, logging a
warning per poll listing affected products and missing keys, plus a debug
log showing the keys that did arrive. After the threshold, accept
Keys Hive may legitimately omit (boost, the colour keys) were kept from
the previous poll for up to five polls, which could report stale state
such as boost ON. Carry over only mode, name, status and target, and
drop the per-product count for products that leave the response.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add `run-file`, `run-live`, `simulate-file`, `simulate-live` targets that start background polling sessions (fixture or real account) and write to logs/. Add `logs` (tail -F), `status` (list runners), `stop` (kill runners), and `live-forget` (clear keychain credentials). Ignore logs/ in .gitignore.
Add `make call` target and `--call` flag that send commands to a running session over a Unix socket. Commands include poll, mode/state inspection, drop control, debug/interval adjustment, and device control (set-mode, set-temp, boost, turn-on/off). Device control requires `--allow-writes` flag at session start. Add `make help` target documenting all targets and options. Refactor Makefile to use RUN_FLAGS for shared options and add detailed
@claude

claude Bot commented Oct 15, 2026

Copy link
Copy Markdown

🤖 Claude Code Review

No blocking bugs found. get_mode returning None and the carry-over logic in the polling cache look safe for Home Assistant.

Bugs: none confirmed.

Should fix / questions

  • src/session/polling.py _keep_missing_state: REQUIRED_STATE_KEYS includes target. If a product legitimately stops sending target (for example a hot water or heating product changing mode), the old target is reported for up to 5 polls. I can't confirm from the code that Hive never does this. Please check it against real payloads, or limit the carry-over to mode/name/status.
  • get_mode now returns None instead of logging an error when state.mode is missing. If the mode is BOOST and props.previous.mode is also missing, it still returns None through HIVETOHA.get(None, None). That is safe, but it is untested if no test covers that branch.

Minor

  • scripts/run_session.py: _find matches device.hive_id.endswith(ref), so a short ref such as 1 can match several devices. It then correctly errors with "N devices match". The only cost is a confusing message.
  • The new local runner script is untested. It is outside src/, so it doesn't affect the coverage gate.

Home Assistant check: I fetched climate.py. It reads self.device["status"]["mode"] through HIVE_TO_HASS_STATE.get(...) and self.device["status"]["boost"] == "ON". A None mode therefore gives hvac_mode=None with no crash. The API shape is unchanged. I did not fetch water_heater.py, which has the same pattern.

Not reviewed in depth: the Makefile and the runner's Keychain and socket handling. This is a dev-only tool, and I only skimmed those parts.


Automated review by Claude Code · workflow run

@KJonline
KJonline merged commit 5ce83d2 into dev Oct 15, 2026
11 checks passed
@KJonline
KJonline deleted the fix-heating-mode-keyerror branch October 15, 2026 18:00
@codecov

codecov Bot commented Oct 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.96%. Comparing base (8acdfc3) to head (f100251).
⚠️ Report is 3 commits behind head on dev.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##              dev     #166   +/-   ##
=======================================
  Coverage   99.96%   99.96%           
=======================================
  Files          30       30           
  Lines        2576     2599   +23     
  Branches      297      306    +9     
=======================================
+ Hits         2575     2598   +23     
  Partials        1        1           
Flag Coverage Δ
unittests 99.96% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/devices/heating.py 100.00% <100.00%> (ø)
src/devices/hotwater.py 100.00% <100.00%> (ø)
src/session/__init__.py 100.00% <100.00%> (ø)
src/session/polling.py 99.40% <100.00%> (+0.13%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant