first commit
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
"""API de surveillance des ressources système."""
|
||||
|
||||
import logging
|
||||
from fastapi import APIRouter, Request
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/system/stats")
|
||||
async def system_stats(request: Request):
|
||||
"""Ressources système en temps réel."""
|
||||
sys_svc = request.app.state.system_service
|
||||
return sys_svc.get_stats()
|
||||
|
||||
|
||||
@router.get("/system/services")
|
||||
async def system_services(request: Request):
|
||||
"""Statut des services systemd."""
|
||||
sys_svc = request.app.state.system_service
|
||||
return sys_svc.get_services_status()
|
||||
|
||||
|
||||
@router.get("/system/photobooth")
|
||||
async def photobooth_status(request: Request):
|
||||
"""Vérifie si photobooth-app répond."""
|
||||
pb = request.app.state.photobooth_service
|
||||
alive = await pb.is_alive()
|
||||
return {"alive": alive, "url": request.app.state.config.photobooth.base_url}
|
||||
|
||||
|
||||
@router.post("/system/button/simulate")
|
||||
async def simulate_button(request: Request, clicks: int = 1):
|
||||
"""Simule un appui bouton (dev/test uniquement)."""
|
||||
btn = request.app.state.button_service
|
||||
if clicks == 0:
|
||||
btn.simulate_long_press()
|
||||
else:
|
||||
btn.simulate_click(clicks)
|
||||
return {"ok": True, "simulated_clicks": clicks}
|
||||
|
||||
|
||||
@router.post("/system/relay")
|
||||
async def control_relay(request: Request, state: str = "on"):
|
||||
"""Force le relay ON/OFF."""
|
||||
btn = request.app.state.button_service
|
||||
if state == "on":
|
||||
btn.relay_on()
|
||||
else:
|
||||
btn.relay_off()
|
||||
return {"ok": True, "relay": state}
|
||||
Reference in New Issue
Block a user