From 16e4b1fd4f1bef1b6edcdab9d9107b6332e02cdc Mon Sep 17 00:00:00 2001 From: Andrew Wilkinson Date: Fri, 28 Jun 2024 18:07:44 +0100 Subject: [PATCH] fix: Upgrade to support paho-mqtt>=2.0.0. --- glowprom/mqtt.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/glowprom/mqtt.py b/glowprom/mqtt.py index 3730e6d..5ede29c 100644 --- a/glowprom/mqtt.py +++ b/glowprom/mqtt.py @@ -22,9 +22,16 @@ import paho.mqtt.client as mqtt -def on_connect(topic, client, userdata, flags, rc): - print("Connected with result code "+str(rc)) +def on_connect(topic: str, + client: mqtt.Client, + userdata, + flags, + reason_code, + properties): + if reason_code > 0: + sys.stderr.write(f"Failed to connect to mqtt: {reason_code}") + print("Successfully connected to mqtt broker.") client.subscribe(topic) @@ -41,7 +48,7 @@ def safe_on_message(client, userdata, msg): def connect(args, on_message, retry=True): - client = mqtt.Client() + client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2) client.on_connect = \ functools.partial(on_connect, args.topic if args.cloud else "glow/+/+/+")