From f558b69119fce11ceb28cf9514258c5dd296242d Mon Sep 17 00:00:00 2001 From: sascha Date: Fri, 31 Jul 2026 09:21:22 +0200 Subject: [PATCH] fix: handle Paho v2 reason codes --- collector.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/collector.py b/collector.py index 2c5d961..7906b82 100644 --- a/collector.py +++ b/collector.py @@ -162,7 +162,9 @@ def enqueue(metric_line): def on_connect(client, userdata, flags, reason_code, properties=None): - ok = int(reason_code) == 0 + # Paho v2 passes a ReasonCode object; direct comparison is supported, + # converting it with int() is not. + ok = reason_code == 0 with lock: state["mqtt_up"] = 1 if ok else 0 if ok: @@ -337,7 +339,7 @@ class HealthHandler(BaseHTTPRequestHandler): return with lock: payload = { - "status": "ok" if state["influx_up"] else "degraded", + "status": "ok" if state["influx_up"] and state["mqtt_up"] else "degraded", "mqtt_up": bool(state["mqtt_up"]), "influx_up": bool(state["influx_up"]), "homeassistant_up": bool(state["ha_up"]), "homeassistant_http_status": state["ha_http_status"], "topics_seen": len(state["topics"]), "messages_total": state["messages_total"], @@ -345,7 +347,7 @@ class HealthHandler(BaseHTTPRequestHandler): "uptime_seconds": int(time.time() - state["started"]), } body = json.dumps(payload, separators=(",", ":")).encode() - self.send_response(200 if payload["influx_up"] else 503) + self.send_response(200 if payload["influx_up"] and payload["mqtt_up"] else 503) self.send_header("Content-Type", "application/json") self.send_header("Content-Length", str(len(body))) self.end_headers()