diff --git a/scheduler.py b/scheduler.py index 1025e9a..23b183c 100644 --- a/scheduler.py +++ b/scheduler.py @@ -67,7 +67,7 @@ def poll_status(): for row in conn.execute("SELECT key, value FROM settings").fetchall(): settings[row["key"]] = row["value"] - # Get all active users with assignments (auch ohne personal_nr) + # Get all active users with assignments users_with_assignments = conn.execute(""" SELECT u.azure_id, u.display_name, u.personal_nr, a.segment, d.hostname, @@ -112,64 +112,69 @@ def _process_user(user, aida_lines, settings, conn): last_aida = user["last_aida_status"] or "" last_teams = user["last_teams_status"] or "" - # Determine AIDA status (kann None sein wenn keine CSV oder keine Personalnr) - aida_status = determine_aida_status(aida_lines, personal_nr, settings) - - # Immer Teams-Status abfragen + # Immer Teams-Status abfragen (fuer Dashboard-Anzeige) teams_status = "" presence = graph.get_presence(azure_id) if presence and "activity" in presence: teams_status = "teams_" + presence["activity"].lower() - # Wenn AIDA nicht verfuegbar, nur Teams-Status nutzen - if aida_status is None: - aida_status = "anwesend" # Default: anwesend wenn AIDA nicht verfuegbar + # AIDA-Status ermitteln + aida_status = determine_aida_status(aida_lines, personal_nr, settings) - # Check if status changed + # Check if anything changed if aida_status == last_aida and teams_status == last_teams: return # No change - # Determine color - if aida_status == "abwesend": - color = get_color_for_status("abwesend", conn) - elif aida_status == "homeoffice": - color = get_color_for_status("homeoffice", conn) - elif teams_status: - color = get_color_for_status(teams_status, conn) - else: - color = get_color_for_status("available", conn) - - # Build URL and call WLED - url = build_wled_url( - hostname, color["r"], color["g"], color["b"], - segment=segment, effect=color.get("effect", "") + # --- WLED nur steuern wenn AIDA-Status bekannt --- + wled_changed = aida_status is not None and ( + aida_status != last_aida or + (aida_status == "anwesend" and teams_status != last_teams) ) - success, result_text = call_wled(url) - if success: - conn.execute(""" - INSERT INTO state (user_azure_id, last_aida_status, last_teams_status, updated_at) - VALUES (?, ?, ?, ?) - ON CONFLICT(user_azure_id) - DO UPDATE SET last_aida_status=?, last_teams_status=?, updated_at=? - """, ( - azure_id, aida_status, teams_status, datetime.now(), - aida_status, teams_status, datetime.now(), - )) - conn.commit() - logger.info( - "%-40s aida=%-12s teams=%-20s -> %s", - display_name, aida_status, teams_status, result_text, + if wled_changed: + # Farbe bestimmen nach Originallogik: + # abwesend -> abwesend-Farbe + # homeoffice -> homeoffice-Farbe + # anwesend -> Teams-Farbe + if aida_status == "abwesend": + color = get_color_for_status("abwesend", conn) + elif aida_status == "homeoffice": + color = get_color_for_status("homeoffice", conn) + elif aida_status == "anwesend" and teams_status: + color = get_color_for_status(teams_status, conn) + else: + color = get_color_for_status("available", conn) + + url = build_wled_url( + hostname, color["r"], color["g"], color["b"], + segment=segment, effect=color.get("effect", "") ) - else: - conn.execute(""" - INSERT INTO state (user_azure_id, last_aida_status, last_teams_status, updated_at) - VALUES (?, '', '', ?) - ON CONFLICT(user_azure_id) - DO UPDATE SET last_aida_status='', last_teams_status='', updated_at=? - """, (azure_id, datetime.now(), datetime.now())) - conn.commit() + success, result_text = call_wled(url) - log_activity( - azure_id, display_name, aida_status, teams_status, url, result_text + if not success: + logger.warning("WLED Fehler fuer %s: %s", display_name, result_text) + + log_activity( + azure_id, display_name, + aida_status or "-", teams_status or "-", + url, result_text, + ) + + # State immer aktualisieren (fuer Dashboard) + conn.execute(""" + INSERT INTO state (user_azure_id, last_aida_status, last_teams_status, updated_at) + VALUES (?, ?, ?, ?) + ON CONFLICT(user_azure_id) + DO UPDATE SET last_aida_status=?, last_teams_status=?, updated_at=? + """, ( + azure_id, + aida_status or last_aida, teams_status, datetime.now(), + aida_status or last_aida, teams_status, datetime.now(), + )) + conn.commit() + + logger.info( + "%-40s aida=%-12s teams=%-20s wled=%s", + display_name, aida_status or "-", teams_status, + "aktualisiert" if wled_changed else "nur Dashboard", ) diff --git a/templates/dashboard.html b/templates/dashboard.html index c8db05e..8f5e244 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -38,19 +38,51 @@
Segment {{ seg.index }} {% if seg.user %} - {% if seg.aida == '-' %} -
- - {{ seg.user }} -
- Warte auf Status... - {% else %} -
- - {{ seg.user }} -
- {{ seg.aida }} / {{ seg.teams }} - {% endif %} + {% if seg.aida == '-' and seg.teams == '-' %} +
+ + {{ seg.user }} +
+ Warte auf Status... + {% else %} +
+ + {{ seg.user }} +
+
+ {% if seg.aida == 'anwesend' %} + Anwesend + {% elif seg.aida == 'abwesend' %} + Abwesend + {% elif seg.aida == 'homeoffice' %} + Homeoffice + {% else %} + {{ seg.aida }} + {% endif %} + + {% if seg.teams != '-' %} + {% if 'available' in seg.teams %} + Verfuegbar + {% elif 'busy' in seg.teams or 'inacall' in seg.teams or 'inameeting' in seg.teams %} + Beschaeftigt + {% elif 'donotdisturb' in seg.teams %} + Nicht stoeren + {% elif 'away' in seg.teams or 'berightback' in seg.teams %} + Abwesend + {% elif 'offline' in seg.teams %} + Offline + {% elif 'presenting' in seg.teams %} + Praesentiert + {% elif 'outofoffice' in seg.teams %} + Nicht im Buero + {% elif 'inactive' in seg.teams or 'offwork' in seg.teams %} + Inaktiv + {% else %} + {{ seg.teams }} + {% endif %} + {% endif %} +
+ {% endif %} {% else %}
Nicht zugeordnet