From 001b21faf8de8d13ee5ecc3442617551f220f1f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A2n=20Nguy=E1=BB=85n=20Duy?= Date: Tue, 24 Jun 2025 09:29:40 +0000 Subject: [PATCH] Update tracker for status offline dont publish string or number --- sensor_tracker.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/sensor_tracker.py b/sensor_tracker.py index 66fef96..2df04d4 100644 --- a/sensor_tracker.py +++ b/sensor_tracker.py @@ -101,13 +101,10 @@ class SensorTracker: alert_message = { "alert_type": "sensor_failure", - "timestamp": datetime.now(LOCAL_TIMEZONE).isoformat(), - "sensor_id": sensor_id, - "sensor_ip": sensor["ip"], "sensor_location": sensor["location"], "sensor_type": sensor["type"], "consecutive_failures": sensor["consecutive_failures"], - "last_error": sensor.get("last_error", "Unknown error"), + "last_error": sensor.get("last_error"), "severity": "critical" } @@ -128,9 +125,6 @@ class SensorTracker: alert_message = { "alert_type": "sensor_recovery", - "timestamp": datetime.now(LOCAL_TIMEZONE).isoformat(), - "sensor_id": sensor_id, - "sensor_ip": sensor["ip"], "sensor_location": sensor["location"], "sensor_type": sensor["type"], "consecutive_successes": sensor["consecutive_successes"], @@ -156,14 +150,14 @@ class SensorTracker: # Publish offline status to match online sensor structure topics_data = [ (f"{base_topic}/Time", current_time), - (f"{base_topic}/Status", "offline"), - (f"{base_topic}/Temperature/temperature", "offline"), - (f"{base_topic}/Humidity/humidity", "offline") + (f"{base_topic}/Status"), + (f"{base_topic}/Temperature/temperature"), + (f"{base_topic}/Humidity/humidity") ] # Add CO2 topic for CO2 sensors if host_info["type"] == "cwt_co2": - topics_data.append((f"{base_topic}/CO2/CO2", "offline")) + topics_data.append((f"{base_topic}/CO2/CO2")) # Publish offline status for topic, value in topics_data: