feat: background device status check every 240s instead of on page load
- Add online, leds, version, last_check columns to wled_devices table - Background job checks all WLED devices every 4 minutes - Initial check on startup - Devices page reads status from DB (instant page load) - 'Alle jetzt pruefen' button triggers manual check Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+27
-1
@@ -3,7 +3,7 @@ import os
|
||||
from datetime import datetime
|
||||
|
||||
from database import get_db, get_setting, log_activity
|
||||
from wled_client import build_wled_url, call_wled
|
||||
from wled_client import build_wled_url, call_wled, get_wled_info
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -197,3 +197,29 @@ def _process_user(user, aida_lines, settings, conn):
|
||||
display_name, aida_status or "-", teams_status,
|
||||
"aktualisiert" if wled_changed else "nur Dashboard",
|
||||
)
|
||||
|
||||
|
||||
def check_devices():
|
||||
"""Check all WLED devices and store status in DB. Called periodically."""
|
||||
conn = get_db()
|
||||
try:
|
||||
devices = conn.execute("SELECT id, hostname FROM wled_devices").fetchall()
|
||||
for dev in devices:
|
||||
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(),
|
||||
dev["id"],
|
||||
))
|
||||
conn.commit()
|
||||
logger.info("Device-Check: %d Geraete geprueft", len(devices))
|
||||
except Exception as e:
|
||||
logger.error("Device-Check Fehler: %s", e)
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
Reference in New Issue
Block a user