chore: fichiers modifiés sessions précédentes
🚀 Deploy — JH Photomaton / 🔍 Vérification (push) Has been cancelled
🚀 Deploy — JH Photomaton / 🍓 Deploy sur le Pi (push) Has been cancelled

This commit is contained in:
2026-07-17 17:19:57 +02:00
parent 8a70dea240
commit 31f4023f16
40 changed files with 8211 additions and 0 deletions
+33
View File
@@ -68,6 +68,9 @@ async def lifespan(app: FastAPI):
button_svc = ButtonService(config, led_svc, photobooth_svc, ws_manager, loop)
button_svc.start()
# Injection du service LED dans le printer_service (pour LED après impression background)
printer_svc.set_led_service(led_svc)
app.state.config = config
app.state.config_service = config_svc
app.state.ws_manager = ws_manager
@@ -79,6 +82,7 @@ async def lifespan(app: FastAPI):
app.state.event_service = event_svc
stats_task = asyncio.create_task(_system_stats_loop(system_svc, ws_manager))
printer_task = asyncio.create_task(_printer_monitor_loop(printer_svc, led_svc, ws_manager))
logger.info("JH Photomaton demarre -- port %d", config.app.port)
led_svc.play("idle")
@@ -86,6 +90,7 @@ async def lifespan(app: FastAPI):
yield
stats_task.cancel()
printer_task.cancel()
button_svc.stop()
led_svc.stop()
await photobooth_svc.close()
@@ -94,6 +99,34 @@ async def lifespan(app: FastAPI):
logger.info("JH Photomaton arrete")
async def _printer_monitor_loop(printer_svc: PrinterService, led_svc: LEDService, ws: WSManager):
"""Surveille les imprimantes toutes les 30s et joue l'effet error si une est en panne."""
# Effets qui ne doivent pas être écrasés par le moniteur
ACTIVE_EFFECTS = {"countdown", "capture", "captured", "printing", "finished"}
await asyncio.sleep(15) # délai initial pour laisser les services démarrer
while True:
try:
statuses = await printer_svc.get_printers_status()
has_error = any(
s.get("state") in ("disabled", "error", "offline")
or bool(s.get("reasons"))
for s in statuses
)
current = led_svc.current_effect
if current not in ACTIVE_EFFECTS:
if has_error and current != "error":
led_svc.play("error")
await ws.broadcast({"type": "led_effect", "effect": "error"})
logger.info("Moniteur imprimante: erreur détectée → LED error")
elif not has_error and current == "error":
led_svc.play("idle")
await ws.broadcast({"type": "led_effect", "effect": "idle"})
logger.info("Moniteur imprimante: erreur résolue → LED idle")
except Exception as e:
logger.debug("Printer monitor: %s", e)
await asyncio.sleep(30)
async def _system_stats_loop(sys_svc: SystemService, ws: WSManager):
while True:
try: