Skip to content

feat: add get_schedule/set_schedule for heating and hot water - #173

Merged
KJonline merged 3 commits into
Pyhass:devfrom
matt-thepie:feat/set-schedule
Nov 2, 2026
Merged

KJonline merged 3 commits into
Pyhass:devfrom
matt-thepie:feat/set-schedule

Conversation

@matt-thepie

Copy link
Copy Markdown
Contributor

Summary

Adds schedule writing for heating and hot water, requested in #19.

  • New ScheduleMixin (src/devices/schedule.py), composed into HiveHeating and HiveHotwater.
  • get_schedule(device) returns an editable deep copy of the seven-day schedule.
  • set_schedule(device, schedule) validates and normalises the week (drops extra keys the Hive web app adds, sorts slots, raises ValueError on bad input), posts all seven days (Hive only accepts full-week updates), then re-reads the product and returns False if Hive answered 200 but ignored the change.
  • camelCase aliases getSchedule / setSchedule in helper/compat_aliases.py.
  • README section and examples/example_set_schedule.py, a round-trip example that edits one slot, verifies it, and restores the original.

Home Assistant impact

Additive only. Nothing in the HA hive integration calls these methods; climate.py and water_heater.py on dev use setMode, setTargetTemperature, setBoostOn/Off only. No existing method, return shape or device.status key changes.

Testing

  • Full suite: 1091 passed, coverage 100%. ruff, mypy, pylint 10/10, bandit clean.
  • Live round trip on a trvcontrol zone: slot edit stored and restored correctly (set_schedule returned True both times, re-read schedules matched).
  • Hot water is covered by file-mode tests only; I have a combi boiler so no hotwater product to test against. Someone with a Hive hot water zone could confirm with the example (swap hive.heating for hive.hotwater).

Note: running the example against the live service today also needs #169, since the Hive SSO login page changed on 2026-10-20.

Closes #19

🤖 Generated with Claude Code

Adds ScheduleMixin (src/devices/schedule.py), composed into HiveHeating and
HiveHotwater. get_schedule returns an editable copy of the weekly schedule;
set_schedule validates and normalises the week, posts all seven days (Hive
only accepts full-week updates), then re-reads the product and returns False
if Hive silently ignored the change. camelCase aliases getSchedule/setSchedule
are included for HA compatibility.

Verified live on a trvcontrol zone: slot edit stored and restored correctly.

Closes Pyhass#19

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (dev@0294877). Learn more about missing BASE report.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff           @@
##             dev     #173   +/-   ##
======================================
  Coverage       ?   99.96%           
======================================
  Files          ?       31           
  Lines          ?     2717           
  Branches       ?      323           
======================================
  Hits           ?     2716           
  Misses         ?        0           
  Partials       ?        1           
Flag Coverage Δ
unittests 99.96% <100.00%> (?)

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/devices/schedule.py 100.00% <100.00%> (ø)
src/helper/compat_aliases.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@KJonline KJonline added the claude-review Run Claude code review on this PR (required for fork PRs) label Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

🤖 Claude Code Review

Looks good to merge. I found no blocking bugs, and the change is additive only.

Bugs: none confirmed.

Should fix (minor, not blocking):

  • src/devices/schedule.py:60-65: get_schedule copies the whole slot value dict, but _normalise_slot keeps only value_key. set_schedule then compares the two with stored != normalised. If Hive ever returns an extra key inside a slot's value, the comparison fails and set_schedule returns False even though the write succeeded. The same applies to a slot with extra keys outside value, which get_schedule already drops. The author tested a trvcontrol live but not hotwater. I'd compare only the normalised view: stored = self._normalise_schedule(stored_raw, value_key), or build the get_schedule copy through the same slot normaliser.
  • get_schedule does slot["start"] and slot["value"] with no guard. A malformed slot in the Hive payload would raise KeyError. This is unlikely, but _get_product_state is otherwise careful to return None on missing keys.

Minor:

  • set_schedule is declared as returning bool, but it raises ValueError on bad input. The docstring says so, so this is fine. Callers should be aware of it.

Home Assistant check: I fetched climate.py from home-assistant/core (dev). It calls only setMode, setTargetTemperature, setBoostOn, setBoostOff, getClimate and session.updateData. For example: await self.hive.heating.setMode(self.device, new_mode). Nothing uses getSchedule or setSchedule, and no existing method or device.status key changes. I did not fetch water_heater.py, but the PR description says it uses only mode and boost calls.

Not reviewed: I did not run the test suite and did not read tests/module/test_schedule.py or the example script in detail. Codecov reports the changed lines are covered.


Automated review by Claude Code · workflow run

@KJonline
KJonline merged commit 3648b67 into Pyhass:dev Nov 2, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

claude-review Run Claude code review on this PR (required for fork PRs)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] setting the schedule for heat & water

2 participants