feat: Restore 3 routine controls (advance, swap, pause, resume, snooze, stop)#54
Closed
kristofferR wants to merge 1 commit into
Closed
feat: Restore 3 routine controls (advance, swap, pause, resume, snooze, stop)#54kristofferR wants to merge 1 commit into
kristofferR wants to merge 1 commit into
Conversation
…nooze, stop) Mirrors what the physical Restore 3 buttons do, so HA automations can drive (and be driven by) the same gestures: - `advance_step` — Big Button single-press while a routine is playing. Uses cached favorite step counts to gate, writes `current.step` to the AWS IoT shadow. - `swap_routine` — Swap button. Async; flips the active swappable routine via the new `Hatch.bulk_edit_swappables()` REST call against `/service/app/routine/v2/bulkEditSwappables`, with confirmDataVersion follow-up on the envelope. - `pause_routine` / `resume_routine` — Pause button toggle, writes `current.paused`. Tracks `paused` from the inbound shadow. - `snooze_alarm` — Big Button while alarm sounds. Writes `snooze.active=true` with `startTime`. Surfaces `is_snoozed`, `snooze_start_time`, `snooze_duration_seconds` from the shadow. - `stop_routine` — Big Button long-press, alias for `turn_off()`. Also exposes derived helpers `swappable_routines`, `can_swap_routine`, `routine_step_count`, `can_advance_step`, `_playing_routine` to let the Home Assistant integration gate button availability. Adds 20 unit tests covering each method's edge cases.
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the routine-control surface that the Restore 3's three on-device buttons expose, so Home Assistant automations can drive (and be driven by) the same gestures the physical buttons do.
advance_step— Big Button single-press while a routine is playing. Writescurrent.stepto the AWS IoT shadow, gated by step count from the cached favorites payload.swap_routine— Swap button. Async; flips the active swappable routine via the newHatch.bulk_edit_swappables()REST call against/service/app/routine/v2/bulkEditSwappables, withconfirmDataVersionfollow-up on the envelope.pause_routine/resume_routine— Pause button toggle, writescurrent.paused. Tracks the inboundcurrent.pausedshadow value.snooze_alarm— Big Button while an alarm sounds. Writessnooze.active=truewithstartTime. Surfacesis_snoozed,snooze_start_time,snooze_duration_secondsfrom the shadow.stop_routine— Big Button long-press, alias forturn_off().Helpers
swappable_routines,can_swap_routine,routine_step_count,can_advance_step,_playing_routineare exposed so the integration can gate button availability cleanly.The shadow keys (
current.step,current.paused,snooze.active,snooze.startTime) and thebulkEditSwappablesREST endpoint were derived from APK reverse engineering of the Hatch Sleep Android app (v6.13.2).Test plan
uv run pytest tests/test_restore_v5.py -v— 20 tests, all passha_hatchPR: physical Big Button advance / Swap / Pause / Resume mirror behavior of the new methodsbulkEditSwappablespayload shape (full ScheduledRoutine echoed back) matches what Hatch's API actually accepts — the field-name inference may surface a mismatch on first real call