diff --git a/app.py b/app.py index 1356c7f..052fa61 100644 --- a/app.py +++ b/app.py @@ -202,9 +202,20 @@ async def toggle_user(azure_id: str): @app.get("/devices", response_class=HTMLResponse) async def devices_page(request: Request): conn = database.get_db() - devices = conn.execute( + devices_raw = conn.execute( "SELECT * FROM wled_devices ORDER BY name, hostname" ).fetchall() + # Letzte Aktivitaet pro Device aus activity_log + devices = [] + for dev in devices_raw: + last_act = conn.execute(""" + SELECT MAX(l.timestamp) as la + FROM activity_log l + WHERE l.wled_url LIKE '%' || ? || '%' + """, (dev["hostname"],)).fetchone() + d = dict(dev) + d["last_activity"] = last_act["la"] if last_act and last_act["la"] else None + devices.append(d) last_check_row = conn.execute( "SELECT MAX(last_check) as lc FROM wled_devices WHERE last_check IS NOT NULL" ).fetchone() diff --git a/templates/devices.html b/templates/devices.html index 83b2c30..df0952e 100644 --- a/templates/devices.html +++ b/templates/devices.html @@ -29,6 +29,7 @@