diff --git a/app.py b/app.py index 269afe1..6daed2a 100644 --- a/app.py +++ b/app.py @@ -256,6 +256,27 @@ async def check_all_devices(): return RedirectResponse("/devices", status_code=303) +@app.post("/api/devices/{device_id}/check") +async def check_single_device(device_id: int): + from wled_client import get_wled_info + conn = database.get_db() + dev = conn.execute("SELECT hostname FROM wled_devices WHERE id=?", (device_id,)).fetchone() + if dev: + from datetime import datetime + info = get_wled_info(dev["hostname"]) + conn.execute(""" + UPDATE wled_devices SET online=?, leds=?, version=?, last_check=? WHERE id=? + """, ( + 1 if info.get("online") else 0, + info.get("leds", 0) if info.get("online") else 0, + info.get("version", "") if info.get("online") else "", + datetime.now(), device_id, + )) + conn.commit() + conn.close() + return RedirectResponse("/devices", status_code=303) + + # ── Assignments ──────────────────────────────────────────────────────────── @app.get("/assignments", response_class=HTMLResponse) diff --git a/templates/devices.html b/templates/devices.html index 8311691..ebc3cf6 100644 --- a/templates/devices.html +++ b/templates/devices.html @@ -55,6 +55,11 @@ {{ device.version if device.version else '-' }} {{ device.segment_count }} +
+ +