Skip to content

feat: Restore 3 routine controls (advance, swap, pause, resume, snooze, stop)#54

Closed
kristofferR wants to merge 1 commit into
dahlb:mainfrom
kristofferR:restore3-controls
Closed

feat: Restore 3 routine controls (advance, swap, pause, resume, snooze, stop)#54
kristofferR wants to merge 1 commit into
dahlb:mainfrom
kristofferR:restore3-controls

Conversation

@kristofferR
Copy link
Copy Markdown
Contributor

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. Writes current.step to 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 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 the inbound current.paused shadow value.
  • snooze_alarm — Big Button while an 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().

Helpers swappable_routines, can_swap_routine, routine_step_count, can_advance_step, _playing_routine are exposed so the integration can gate button availability cleanly.

The shadow keys (current.step, current.paused, snooze.active, snooze.startTime) and the bulkEditSwappables REST 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 pass
  • End-to-end on a real Restore 3 via the companion ha_hatch PR: physical Big Button advance / Swap / Pause / Resume mirror behavior of the new methods
  • Verify bulkEditSwappables payload shape (full ScheduledRoutine echoed back) matches what Hatch's API actually accepts — the field-name inference may surface a mismatch on first real call

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