feat: add full clock display control for RestoreV5/V4 (day/night brightness, mode, schedule, tap-to-show)#313
Merged
Conversation
…, mode, schedule, tap-to-show)
Owner
|
Looks great. Please fix the simple complaint from ruff then I'll merge it |
Contributor
Author
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
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).
This integration PR consumes the clock-schedule parsing and
turn_clock_offbrightness-preserving fix from the companion library release. It relies on the library exposingclock_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 slidersClockDaytimeBrightnessNumber→number.<device>_clock_daytime_brightness(native_value=clock_daytime, set →set_clock(daytime_brightness=…)).ClockNighttimeBrightnessNumber→number.<device>_clock_nighttime_brightness(native_value=clock_nighttime, set →set_clock(nighttime_brightness=…)).select.py(new) —Clock ModeAlways On,Off at Night,Always Off.current_optionis keyed offclock_turn_off_mode:"always"→ Always Off,"custom"→ Off at Night,"never"→ Always On (falls back tois_clock_onuntil 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_optionwrites the same shadow the Hatch app writes for each mode:{"clock": {"flags": flags | RIOT_FLAGS_CLOCK_ON, "turnOffMode": "never"}}{"clock": {"flags": flags | RIOT_FLAGS_CLOCK_ON, "turnOffMode": "custom"}}{"clock": {"flags": flags & ~RIOT_FLAGS_CLOCK_ON, "turnOffMode": "always"}}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 awareclock_turn_off_mode == "custom"and now is withinturnBrightAt→turnDimAt→ daytime; otherwise nighttime. (Verified on hardware: with Always On, the device displays the nighttime channel.)brightnessreads the active channel;turn_onwrites only the active channel viaset_clock(daytime_brightness=…)/set_clock(nighttime_brightness=…).switch.py(edit) —Clock Tap to ShowHatchClockTapSwitchtogglesRIOT_FLAGS_CLOCK_IGNORE_TAP.is_on= clock reacts to tap (flag clear); off = ignore tap.time.py(edit) — clock schedule timesTimeEntitys matching the single on/off schedule the Hatch app exposes:Clock Turn On At— readsclock_turn_on_at, writes bothturnOnAtandturnBrightAt.Clock Turn Off At— readsclock_turn_off_at, writes bothturnOffAtandturnDimAt.const.py(edit) — addPlatform.NUMBERandPlatform.SELECTtoPLATFORMS.manifest.json(edit) — bumped tohatch_rest_api==1.34.0, which includes the clock-schedule parsing andturn_clock_offfix this PR relies on.Behavior notes
set_clockalways setsRIOT_FLAGS_CLOCK_ON, so moving a brightness slider while the clock is off turns it on (existing library semantics). UseClock Modefor on/off.Testing
py_compileclean.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.