Harden main loop and store; by-id device default, BOARD_TZ

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
rickzkmandClaude Sonnet 5.5 committed 2026-10-07 00:55:46 +02:00
1 parent 8649d3abd0
commit 44a1b3cf8c
7 files changed
+100 -30

No files matched your search

+15
View File
@@ -1,4 +1,5 @@
"""Testable glue between timetables, schedule and the board (no screen, no network)."""
import logging
from datetime import date, datetime, timedelta
from typing import Container, Sequence
from zoneinfo import ZoneInfo
@@ -6,9 +7,12 @@ from zoneinfo import ZoneInfo
from PIL import Image
import board
import store
from schedule import next_departures
from timetable import Timetable
log = logging.getLogger(__name__)
DEFAULT_TZ = "Europe/Prague"
REFRESH_HOUR = 3
RETRY = timedelta(minutes=15)
@@ -29,6 +33,17 @@ def refresh_due(last_attempt: datetime | None, now: datetime, last_ok: bool) ->
return last_attempt < today_refresh <= now
def load_cache(
lines, data_dir, now: datetime, previous_timetables: list[Timetable], previous_stale: bool
) -> tuple[list[Timetable], bool]:
"""Load the cached timetables and staleness; on any error keep the previous values."""
try:
return store.load_timetables(lines, data_dir), store.is_stale(lines, data_dir, now)
except Exception:
log.exception("loading the cache failed")
return previous_timetables, previous_stale
def board_image(
timetables: Sequence[Timetable],
now: datetime,