feat(signage,scenes): schedule lines with screens and smart days, screens' defaults, horizontal timeline, scenes
- Scenes (Alembic 0043, models/scene.py, /api/scenes, core.scenes.manage): named modes on or off (optionally until a time); price rules / deals get the condition "a scene is on"; signage lines can play only during a scene; turning one on tells every screen and pushes the online menu. - Signage schedules are lines (signage_schedule_items): playlist, screens ([] = every screen), priority, days, smart days (1st / last day, first / last week, Greek public holidays or not: core/calendar_days.py, mirrored in @xenia/signage), hours, dates, scene. No line → the screen's default playlist. 0043 turns the old named schedules into lines for their screens. - Screens: default playlist, TV shape, turn; what plays now and why. - Manager: tabs Screens · Playlists · Schedules · Slides (placeholder) · Message and weather; schedule lines with playlist / screens / priority / delete on one line; the playlist editor's horizontal timeline of fixed cards, the slide's basics beside its preview (one height), then its content; Management → Scenes; the scene condition in pricing. - Tests: backend (lines, smart days, scenes, prices), player logic, e2e. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
"""Scenes (owner 2026-11-21, models/scene.py): which are on now, and telling what follows them.
|
||||
|
||||
A scene is on when it was turned on and its `until` (if any) has not passed. When scenes change,
|
||||
the signage screens are told (their schedules may pick another playlist) and the prices are
|
||||
recomputed by whoever asks next (price rules read `active_ids` through the pricing context).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from core.timeutil import utcnow
|
||||
|
||||
|
||||
def _aware(dt):
|
||||
from datetime import timezone
|
||||
return dt if dt is None or dt.tzinfo else dt.replace(tzinfo=timezone.utc)
|
||||
|
||||
|
||||
def is_on(scene, now: datetime | None = None) -> bool:
|
||||
now = now or utcnow()
|
||||
return bool(scene.is_active) and (scene.until is None or _aware(scene.until) > _aware(now))
|
||||
|
||||
|
||||
def active_ids(db, now: datetime | None = None) -> set[int]:
|
||||
from models.scene import Scene
|
||||
return {s.id for s in db.query(Scene).filter(Scene.is_active.is_(True)) if is_on(s, now)}
|
||||
|
||||
|
||||
def out(scene, now: datetime | None = None) -> dict:
|
||||
return {"id": scene.id, "name": scene.name, "color": scene.color, "description": scene.description,
|
||||
"active": is_on(scene, now), "activated_at": scene.activated_at, "until": scene.until, "sort_order": scene.sort_order}
|
||||
|
||||
|
||||
def changed(db) -> None:
|
||||
"""Scenes changed: the signage screens look again; the dashboards refresh their scene lists."""
|
||||
from services.ws_bus import broadcast_sync
|
||||
broadcast_sync("scenes.changed", {})
|
||||
try:
|
||||
from routers.signage import tell_all_screens
|
||||
tell_all_screens(db)
|
||||
except Exception: # signage off or not loaded: nothing to tell
|
||||
pass
|
||||
Reference in New Issue
Block a user