Skip to content

Commit 8be3ef1

Browse files
authoredMay 2, 2024
Add HA script compat for paho-mqtt 2.0.0 via legacy callback API (#2916)
1 parent 28a846f commit 8be3ef1

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed
 

‎examples/mqtt_rtl_433_test_client.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@
3030

3131
# log = logging.getLogger() # Single process logger
3232
log = mp.log_to_stderr() # Multiprocessing capable logger
33-
mqtt_client = mqtt.Client("RTL_433_Test")
33+
if hasattr(mqtt, 'CallbackAPIVersion'): # paho >= 2.0.0
34+
mqtt_client = mqtt.Client(callback_api_version=mqtt.CallbackAPIVersion.VERSION1, client_id="RTL_433_Test")
35+
else:
36+
mqtt_client = mqtt.Client(client_id="RTL_433_Test")
3437

3538
sensor_state = dict() # Dictionary containing accumulated sensor state
3639

‎examples/rtl_433_mqtt_hass.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,10 @@ def bridge_event_to_hass(mqttc, topic_prefix, data):
984984
def rtl_433_bridge():
985985
"""Run a MQTT Home Assistant auto discovery bridge for rtl_433."""
986986

987-
mqttc = mqtt.Client()
987+
if hasattr(mqtt, 'CallbackAPIVersion'): # paho >= 2.0.0
988+
mqttc = mqtt.Client(callback_api_version=mqtt.CallbackAPIVersion.VERSION1)
989+
else:
990+
mqttc = mqtt.Client()
988991

989992
if args.debug:
990993
mqttc.enable_logger()

‎examples/rtl_433_mqtt_relay.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ def rtl_433_probe():
111111
"""Run a rtl_433 UDP listener."""
112112

113113
## Connect to MQTT
114-
mqttc = mqtt.Client()
114+
if hasattr(mqtt, 'CallbackAPIVersion'): # paho >= 2.0.0
115+
mqttc = mqtt.Client(callback_api_version=mqtt.CallbackAPIVersion.VERSION1)
116+
else:
117+
mqttc = mqtt.Client()
115118
mqttc.on_connect = mqtt_connect
116119
mqttc.on_disconnect = mqtt_disconnect
117120
if MQTT_USERNAME != None:

0 commit comments

Comments
 (0)