mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-10-27 08:39:12 +00:00
feat(schedule): per-plugin schedules and hide-while-live (#799)
* feat(schedule): per-plugin schedules and hide-while-live Users asked to turn off news and stocks on gameday so only scores show. Each plugin can now have its own schedule (global or per-day window in which it may show) plus hide_when_live, which hides it whenever any plugin reports a live game. A hidden plugin is skipped in the rotation, the live takeover and the Vegas ticker; it stays loaded, and on-demand still shows it. - src/plugin_schedule.py: the window rule, now shared with the display schedule (_check_schedule calls schedule_state) - core config key plugin_schedules; GET/POST /api/v3/config/plugin-schedules - Schedule page: Plugin Schedules card, one picker per enabled plugin Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(schedule): tolerate wrong-shaped schedules, quiet skipped modes - schedule_state treats a non-string mode, non-dict days or a non-dict day entry as missing instead of raising in the display loop - the run loop no longer warns "No plugin manager found" for a mode it skips: _plugin_to_draw / _plugin_for_mode already log why (a scheduled-off plugin at DEBUG) - Schedule page DOM test: every form is marked data-reports-result, not exactly two (each plugin adds one) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(schedule): guard plugin_schedules shape and the cross-thread cache - a plugin_schedules that is not a dict (list, string) hides nothing instead of raising in the display loop - the hidden-set cache keys on the schedules themselves and is published as one tuple, so a Vegas-thread call still holding the pre-reload config cannot leave its answer standing after a reload; the separate invalidation in _refresh_config_cache is gone Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(schedule): no live hold on a scheduled-off mode; blank an empty rotation - _still_live ignores a plugin its schedule hides, so a rotation landing on a scheduled-off live mode advances instead of holding a mode it skips - once a whole rotation has had nothing to show (every plugin empty or scheduled off), the panel is cleared once instead of leaving the last screen up Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(schedule): push the empty-rotation blank to the web preview clear() alone blanked the matrix but left the preview snapshot on the last frame (seen on ledpi with every plugin scheduled off). Follow it with update_display(), as the scheduled-off blank does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(schedule): write the empty-rotation blank to the preview The preview throttle skipped the blank frame (written 12 s after the last snapshot), and write_owed_snapshot() only runs after a display() call, which an all-empty rotation never makes: on ledpi the preview kept the startup splash while the panel was dark. Flush the owed snapshot on each paused empty pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(schedule): quiet the once-a-second logs when nothing can show With every plugin scheduled off (seen on ledpi), the loop retries once a second and journaled three to four lines each time: Vegas's "No plugins available" WARNING, the coordinator's "Failed to initialize stream manager" ERROR, the 0-plugin rotation summary and "Switching to mode". Vegas now warns once until its list fills again, the coordinator line is DEBUG (initialize only fails for an empty list), and the mode-switch line is DEBUG once a whole rotation has been empty. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(schedule): end the scroll before the empty blank; Vegas sees hidden changes sooner - the empty-rotation blank is controller-drawn, so it ends the last scroll's state first (_end_scroll_before_core_screen), as the scheduled-off blank does - StreamManager.refresh() rebuilds the plugin list when the hidden set changed, even inside its 30 s interval, so a newly hidden plugin leaves at the next scroll group rather than staying for later ones Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -303,7 +303,9 @@ class VegasModeCoordinator:
|
||||
|
||||
# Initialize stream manager
|
||||
if not self.stream_manager.initialize():
|
||||
logger.error("Failed to initialize stream manager")
|
||||
# Only fails with no plugin to show (every one excluded or
|
||||
# scheduled off), which initialize() has logged once.
|
||||
logger.debug("Vegas not started: no plugins to scroll")
|
||||
return False
|
||||
|
||||
# Compose initial content
|
||||
|
||||
@@ -16,7 +16,7 @@ BasePlugin.get_vegas_participation):
|
||||
import logging
|
||||
import threading
|
||||
import time
|
||||
from typing import Optional, List, Dict, Deque, Tuple, TYPE_CHECKING
|
||||
from typing import Callable, Optional, List, Dict, Deque, FrozenSet, Tuple, TYPE_CHECKING
|
||||
from collections import deque
|
||||
from dataclasses import dataclass, field
|
||||
from PIL import Image
|
||||
@@ -75,6 +75,16 @@ class StreamManager:
|
||||
self.config = config
|
||||
self.plugin_manager = plugin_manager
|
||||
self.plugin_adapter = plugin_adapter
|
||||
# Plugin ids to leave out right now (config['plugin_schedules']);
|
||||
# the display controller sets it. Read at each list refresh.
|
||||
# A change to it rebuilds the list at the next refresh() even inside
|
||||
# the refresh interval; segments already composed still scroll out.
|
||||
self.hidden_plugins: Optional[Callable[[], FrozenSet[str]]] = None
|
||||
self._applied_hidden: FrozenSet[str] = frozenset()
|
||||
# True once "no plugins" has been logged, until the list fills again:
|
||||
# with every plugin scheduled off the display retries every second,
|
||||
# and three log lines a second is a full journal on an SD card.
|
||||
self._empty_logged = False
|
||||
|
||||
# Segments composed into the current cycle (swap mode only).
|
||||
self._active_buffer: Deque[ContentSegment] = deque()
|
||||
@@ -106,8 +116,11 @@ class StreamManager:
|
||||
self._refresh_plugin_list()
|
||||
|
||||
if not self._ordered_plugins:
|
||||
logger.warning("No plugins available for Vegas scroll")
|
||||
if not self._empty_logged:
|
||||
logger.warning("No plugins available for Vegas scroll")
|
||||
self._empty_logged = True
|
||||
return False
|
||||
self._empty_logged = False
|
||||
|
||||
# Fill the buffer to a whole cycle's worth of plugins. This used to be
|
||||
# buffer_ahead + 1, which conflated prefetch depth with cycle size and
|
||||
@@ -268,7 +281,9 @@ class StreamManager:
|
||||
Called periodically to pick up new plugins or config changes.
|
||||
"""
|
||||
current_time = time.time()
|
||||
if current_time - self._last_refresh < self._refresh_interval:
|
||||
hidden = self.hidden_plugins() if self.hidden_plugins else frozenset()
|
||||
if (current_time - self._last_refresh < self._refresh_interval
|
||||
and hidden == self._applied_hidden):
|
||||
return
|
||||
|
||||
self._last_refresh = current_time
|
||||
@@ -295,10 +310,15 @@ class StreamManager:
|
||||
# own thread (DisplayController._start_plugin_reload).
|
||||
plugins = list(self.plugin_manager.plugins.items())
|
||||
loaded = len(plugins)
|
||||
hidden = self.hidden_plugins() if self.hidden_plugins else frozenset()
|
||||
self._applied_hidden = hidden
|
||||
for plugin_id, plugin in plugins:
|
||||
if not getattr(plugin, 'enabled', False):
|
||||
logger.debug("[%s] Vegas: skipped (not enabled)", plugin_id)
|
||||
continue
|
||||
if plugin_id in hidden:
|
||||
logger.debug("[%s] Vegas: skipped (scheduled off)", plugin_id)
|
||||
continue
|
||||
|
||||
# 'pause' plugins stay in the rotation: they pause the scroll
|
||||
# for their turn rather than contributing to it.
|
||||
@@ -329,7 +349,8 @@ class StreamManager:
|
||||
|
||||
slots = (f", {len(ordered_plugins)} slots"
|
||||
if len(ordered_plugins) != len(set(ordered_plugins)) else "")
|
||||
logger.info(
|
||||
logger.log(
|
||||
logging.DEBUG if (self._empty_logged and not ordered_plugins) else logging.INFO,
|
||||
"Vegas rotation: %d of %d loaded plugin(s)%s: %s",
|
||||
len(set(ordered_plugins)), loaded, slots, ', '.join(ordered_plugins)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user