From a0c80d934a580766eaa5015418d090acae5a3040 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 12 Jul 2026 14:12:23 +0000 Subject: [PATCH] fix(schedule): stop stray 'days' data from overriding Global schedule save_schedule_config never persisted the schedule's 'mode' field, and _check_schedule inferred per-day vs global purely from whether a 'days' dict was present for the current day. Config migration (_merge_template_defaults) re-adds the template's 'schedule.days' (all days disabled by default) whenever it's missing from the user's saved config - which is exactly the case after saving Global mode, since that save path intentionally pops 'days'. The result: a user on Global mode would get their schedule silently reinterpreted as per-day, with today's day disabled, blanking the display. Persist 'mode' on save and have _check_schedule honor it explicitly (mirroring how _check_dim_schedule already does), so a resurrected 'days' dict can't override an explicit Global selection. Falls back to the old inference behavior only when no 'mode' is recorded. --- src/display_controller.py | 26 ++++++++++++++++++-------- web_interface/blueprints/api_v3.py | 1 + 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/display_controller.py b/src/display_controller.py index 8ae64f34..d9d8fd6c 100644 --- a/src/display_controller.py +++ b/src/display_controller.py @@ -621,18 +621,28 @@ def _check_schedule(self): current_day = current_time.strftime('%A').lower() # e.g. 'monday' current_time_only = current_time.time() - + # Check if per-day schedule is configured days_config = schedule_config.get('days') - - # Determine which schedule to use + + # Determine which schedule to use. Respect an explicit 'mode' field + # (like the dim schedule does) so a stray/legacy 'days' dict left over + # from config migration or a prior per-day setup can't silently + # override a user's Global schedule selection. + mode = schedule_config.get('mode') + mode_normalized = mode.replace('_', '-') if mode else None + use_per_day = False - if days_config: - # Check if days dict is not empty and contains current day - if days_config and current_day in days_config: + if mode_normalized == 'global': + use_per_day = False + elif mode_normalized == 'per-day': + use_per_day = bool(days_config and current_day in days_config) + elif days_config: + # No explicit mode recorded (legacy config) - fall back to + # inferring from presence of a 'days' dict for the current day. + if current_day in days_config: use_per_day = True - elif days_config: - # Days dict exists but doesn't have current day - fall back to global + else: logger.debug("Per-day schedule exists but %s not configured, using global schedule", current_day) if use_per_day: diff --git a/web_interface/blueprints/api_v3.py b/web_interface/blueprints/api_v3.py index 1cf9d185..60025c2b 100644 --- a/web_interface/blueprints/api_v3.py +++ b/web_interface/blueprints/api_v3.py @@ -329,6 +329,7 @@ def save_schedule_config(): } mode = data.get('mode', 'global') + schedule_config['mode'] = mode if mode == 'global': # Simple global schedule