From 1bf42250b422e6a73ce42d078a565a098b5ba211 Mon Sep 17 00:00:00 2001 From: Christian Mueller Date: Thu, 23 Apr 2026 21:57:07 +0200 Subject: [PATCH] feat: add WLED device status check (online/offline, LEDs, version) - Query WLED JSON API (/json/info) for device info - Show online/offline status dot, LED count and firmware version - Auto-check all devices on page load - Button to manually check individual or all devices - Fix hostname placeholder to volksheimstaette.de Co-Authored-By: Claude Opus 4.6 (1M context) --- app.py | 11 ++++++++ templates/devices.html | 64 ++++++++++++++++++++++++++++++++++++++++-- wled_client.py | 21 ++++++++++++++ 3 files changed, 93 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 0be192a..ee5e1a9 100644 --- a/app.py +++ b/app.py @@ -243,6 +243,17 @@ async def delete_device(device_id: int): return RedirectResponse("/devices", status_code=303) +@app.get("/api/devices/{device_id}/status") +async def device_status(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() + conn.close() + if not dev: + return {"online": False} + return get_wled_info(dev["hostname"]) + + # ── Assignments ──────────────────────────────────────────────────────────── @app.get("/assignments", response_class=HTMLResponse) diff --git a/templates/devices.html b/templates/devices.html index 52591b7..db6d95b 100644 --- a/templates/devices.html +++ b/templates/devices.html @@ -2,7 +2,12 @@ {% block title %}WLED-Geraete - Busylight{% endblock %} {% block content %} -

WLED-Geraete

+
+

WLED-Geraete

+ +
@@ -12,8 +17,11 @@ + + + @@ -21,12 +29,21 @@ {% for device in devices %} + + + - @@ -101,7 +118,7 @@
+ placeholder="doorlight0027.intra.volksheimstaette.de" required>
@@ -122,3 +139,44 @@
{% endblock %} + +{% block scripts %} + +{% endblock %} diff --git a/wled_client.py b/wled_client.py index 154e72b..dd99a84 100644 --- a/wled_client.py +++ b/wled_client.py @@ -24,3 +24,24 @@ def call_wled(url): except requests.exceptions.RequestException as e: logger.warning("WLED nicht erreichbar: %s - %s", url, e) return False, str(e) + + +def get_wled_info(hostname): + """Query WLED JSON API for device info. Returns dict or None.""" + try: + r = requests.get(f"http://{hostname}/json/info", timeout=TIMEOUT) + if r.status_code == 200: + data = r.json() + return { + "online": True, + "name": data.get("name", ""), + "version": data.get("ver", ""), + "brand": data.get("brand", "WLED"), + "mac": data.get("mac", ""), + "ip": data.get("ip", ""), + "leds": data.get("leds", {}).get("count", 0), + "power_on": data.get("state", {}).get("on", False) if "state" not in data else None, + } + return {"online": False} + except requests.exceptions.RequestException: + return {"online": False}
Status Hostname / IP NameLEDsVersion Segmente Aktionen
+ + {{ device.hostname }} {{ device.name }}-- {{ device.segment_count }} +
+ Noch keine Geraete vorhanden.