v1.2.7-rc2 - Fix bedtime switch and effective-today display (#113, #114)
Pre-releaseSummary
Two related fixes, both verified by capturing the official Family Link web app's network traffic against a real account before coding:
- #113 —
switch.<child>_bedtimeand the matchingfamilylink.enable_bedtime/disable_bedtimeservices only flipped the weekly policy. The bedtime slot already running
tonight stayed on the child device. Same trap as school time before v1.2.7-rc1. - #114 — After the v1.2.7-rc1 school time fix, the switch would visually snap back to its weekly value on the next coordinator refresh, because
is_onwas still reading the
weekly revision. Bedtime had the same latent bug.
What the web app actually does (captured)
When the user toggles bedtime off and confirms "Apply changes to today as well?", the web app sends two calls, in order:
PUT /people/{id}/timeLimit:update— flips the weekly bedtime revision to state 1 (["487088e7-…", 1]).POST /people/{id}/timeLimitOverrides:batchCreatewith[null, account_id, [[null,null,9, …, [action, [start_h,start_m], [end_h,end_m], "CAEQxx"]]], [1]]— posts a per-day
override.
The override references the day via the opaque CAEQxx day_code string (Monday=CAEQAQ … Sunday=CAEQBw), not the [weekday_int, rule_uuid] tuple school time uses. Confirmed
by capturing both school time and bedtime in the same browser session.
There is no DELETE of previous bedtime overrides — the server treats them as keyed by day_code; the newest one for a given day silently supersedes the older. (School time uses a
different uniqueness key and the web app does emit DELETE there, which is why the #111 fix kept that step.)
The dedicated "Ce soir seulement" / Tonight-only dialog sends only step 2 — it lets the user override tonight without touching the weekly policy.
What this PR changes
async_enable_bedtime / async_disable_bedtime (api.py)
Refactored into a single _async_apply_bedtime_today helper that always does both the PUT and the POST. The override window is taken from the weekly bedtime slot matching today
(falls back to 21:30→07:00 if the user has no slot for today). The CAEQxx day_code is computed from dt_util.now().isoweekday().
is_on for both switches (switch.py)
Now reads bedtime_enabled_today / school_time_enabled_today from appliedTimeLimits, which already merges the weekly policy with any daily override Google has applied. Falls back
to the weekly revision only if the today-effective field is unpopulated (e.g. very first refresh).
async_get_applied_time_limits (api.py)
Computes the two new boolean flags by scanning the per-device CAEQ/CAMQ/UUID entries: any entry matching today's weekday with state_flag=2 flips the corresponding flag to True.
Documentation
- Added a "Bedtime daily override pattern" section to
GOOGLE_FAMILY_LINK_API_ANALYSIS.mdexplaining the difference vs. school time and the no-DELETE behavior. - Updated the endpoints table: the bedtime weekly PUT row now carries the same
⚠️ warning as the school time weekly PUT row, and a new "Apply bedtime today" row documents the override
payload.
Risk
- School time control path is untouched — the v1.2.7 fix still applies as-is.
- Bedtime services now always emit two HTTP calls instead of one. The PUT is unchanged from before; the new POST is only doing what the web app already does in identical
conditions. - The
is_onchange is a display-only fix; ifappliedTimeLimitsdoesn't return the new flag (e.g. transient parse failure), the code falls back to the previous behavior.
Test plan
- Toggle
switch.<child>_bedtimeoff during an active bedtime slot — the device should be unlocked within seconds, and the switch should stay off after the coordinator
refresh. - Toggle it back on — the device should be locked again before the next weekly slot.
- Repeat for
switch.<child>_school_timeto confirm #114 (state display) is fixed: switch off, wait > 60s, switch must still show off. - In the Family Link app, toggle bedtime off with "Tonight only" — within ~30-60s, the HA bedtime switch should reflect off without any HA action.
- Conversely, toggling from the app should be picked up by HA correctly.
- Sanity check: existing services (
set_bedtime_schedule,set_school_time_schedule, daily limit, time bonus, device lock) still work unchanged.
Version
Bumps to 1.2.7-rc2.