Skip to content

feat: add full clock display control for RestoreV5/V4 (day/night brightness, mode, schedule, tap-to-show)#313

Merged
dahlb merged 3 commits into
dahlb:mainfrom
MasterDevwi:restore-v5-clock-controls
Jul 2, 2026
Merged

feat: add full clock display control for RestoreV5/V4 (day/night brightness, mode, schedule, tap-to-show)#313
dahlb merged 3 commits into
dahlb:mainfrom
MasterDevwi:restore-v5-clock-controls

Conversation

@MasterDevwi

@MasterDevwi MasterDevwi commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary

The current clock support in Home Assistant is broken and incomplete. In HA today you can turn the clock light entity off, but you effectively can't turn it back on — it comes back dark/appears to do nothing — and adjusting its brightness has no effect.

The root cause is in hatch_rest_api: turning the clock off wipes the device's stored day and night brightness to near-zero (fixed in dahlb/hatch_rest_api#65), so there's nothing to turn back "on" to, and the brightness path doesn't drive the channel the device is actually displaying.

On top of that, HA exposes only that single (broken) brightness light, so the rest of the RestoreV5/V4 clock display — separate day/night brightness, the on/off/dim/bright schedule, the Always On / Off at Night / Always Off mode, and tap-to-show — can't be controlled at all.

This PR fixes the broken light and exposes the full clock display via new number, select, time, and switch entities. Tested locally against real RestoreV5 hardware (fw 10.1.625) and everything works (details below).


Requires hatch_rest_api >= 1.34.0 (dahlb/hatch_rest_api#65, released as v1.34.0). manifest.json is bumped accordingly.

This integration PR consumes the clock-schedule parsing and turn_clock_off brightness-preserving fix from the companion library release. It relies on the library exposing clock_turn_off_mode, clock_turn_off_at, clock_turn_on_at, clock_turn_dim_at, clock_turn_bright_at, all shipped in v1.34.0.

The Hatch app lets you set a daytime and nighttime brightness, choose whether the clock is Always On / Off at Night / Always Off, set the on/off/dim/bright schedule times, and toggle tap-to-show. This PR surfaces all of that in Home Assistant.

New / changed entities (all RestoreV5, which RestoreV4 subclasses)

number.py (new) — brightness sliders

  • ClockDaytimeBrightnessNumbernumber.<device>_clock_daytime_brightness (native_value = clock_daytime, set → set_clock(daytime_brightness=…)).
  • ClockNighttimeBrightnessNumbernumber.<device>_clock_nighttime_brightness (native_value = clock_nighttime, set → set_clock(nighttime_brightness=…)).
  • Both 0–100% sliders.

select.py (new) — Clock Mode

  • Options: Always On, Off at Night, Always Off.
  • current_option is keyed off clock_turn_off_mode: "always" → Always Off, "custom" → Off at Night, "never" → Always On (falls back to is_clock_on until the mode field has been parsed). Reading the mode field rather than the display flag avoids misreporting an Off-at-Night device as Always Off while it is inside its scheduled off window.
  • select_option writes the same shadow the Hatch app writes for each mode:
    • Always On → {"clock": {"flags": flags | RIOT_FLAGS_CLOCK_ON, "turnOffMode": "never"}}
    • Off at Night → {"clock": {"flags": flags | RIOT_FLAGS_CLOCK_ON, "turnOffMode": "custom"}}
    • Always Off → {"clock": {"flags": flags & ~RIOT_FLAGS_CLOCK_ON, "turnOffMode": "always"}}
  • Setting turnOffMode: "always" for Always Off (rather than only clearing the display flag) is what makes the Hatch app reflect the mode change.

light_riot_clock_entity.py (edit) — active-channel aware

  • The clock light now reflects and drives the brightness channel the device is currently displaying instead of always using daytime.
  • Active channel: clock_turn_off_mode == "custom" and now is within turnBrightAtturnDimAt → daytime; otherwise nighttime. (Verified on hardware: with Always On, the device displays the nighttime channel.)
  • brightness reads the active channel; turn_on writes only the active channel via set_clock(daytime_brightness=…) / set_clock(nighttime_brightness=…).
  • Falls back to the old single-channel behavior when a device doesn't expose both channels.

switch.py (edit) — Clock Tap to Show

  • HatchClockTapSwitch toggles RIOT_FLAGS_CLOCK_IGNORE_TAP.
  • is_on = clock reacts to tap (flag clear); off = ignore tap.

time.py (edit) — clock schedule times

  • Two TimeEntitys matching the single on/off schedule the Hatch app exposes:
    • Clock Turn On At — reads clock_turn_on_at, writes both turnOnAt and turnBrightAt.
    • Clock Turn Off At — reads clock_turn_off_at, writes both turnOffAt and turnDimAt.
  • The device stores the display-on and dim/bright transitions as separate keys, but the app presents a single "on" and a single "off" time, so each entity writes both keys in its pair to keep them in sync.
  • The existing alarm wake-time entities are untouched.

const.py (edit) — add Platform.NUMBER and Platform.SELECT to PLATFORMS.

manifest.json (edit) — bumped to hatch_rest_api==1.34.0, which includes the clock-schedule parsing and turn_clock_off fix this PR relies on.

Behavior notes

  • set_clock always sets RIOT_FLAGS_CLOCK_ON, so moving a brightness slider while the clock is off turns it on (existing library semantics). Use Clock Mode for on/off.
  • All writes are partial shadow deltas, matching how the app updates the device.

Testing

  • All files py_compile clean.
  • Live RestoreV5 (fw 10.1.625): day+night sliders read back and update the device independently; Clock Mode switches Always On / Off at Night / Always Off; schedule times round-trip; tap-to-show toggles. Active-channel light confirmed by setting night=10% / day=100% in Always On and observing the physical clock go dim.

Splitting

If a single PR is too large, this can be split into: (1) day+night numbers, (2) active-channel light, (3) clock mode select, (4) on/off schedule times, (5) tap-to-show switch — each independent once the library dependency is in place.

@MasterDevwi MasterDevwi changed the title Add full clock display control for RestoreV5/V4 (day/night brightness, mode, schedule, tap-to-show) feat: add full clock display control for RestoreV5/V4 (day/night brightness, mode, schedule, tap-to-show) Jul 2, 2026
@MasterDevwi MasterDevwi marked this pull request as ready for review July 2, 2026 14:54
@dahlb

dahlb commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Looks great.

Please fix the simple complaint from ruff then I'll merge it

@MasterDevwi

MasterDevwi commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @dahlb! Fixed in a808f4b.

@dahlb dahlb merged commit 5ce47c8 into dahlb:main Jul 2, 2026
4 checks passed
@MasterDevwi MasterDevwi deleted the restore-v5-clock-controls branch July 2, 2026 16:00
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.

2 participants