mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-06-12 18:41:27 +02:00
Refactor MQTT client initialization
https://github.com/alexbelgium/hassio-addons/issues/2199#issuecomment-3536598328
This commit is contained in:
@@ -112,15 +112,17 @@ def automatic_mqtt_publish(file, detection, path):
|
|||||||
mqttc.publish(mqtt_topic, json_bird, 1)
|
mqttc.publish(mqtt_topic, json_bird, 1)
|
||||||
log.info("Posted to MQTT: ok")
|
log.info("Posted to MQTT: ok")
|
||||||
|
|
||||||
|
|
||||||
# Create MQTT client using legacy callback API when available for
|
# Create MQTT client using legacy callback API when available for
|
||||||
# compatibility with paho-mqtt >= 2.0
|
# compatibility with paho-mqtt >= 2.0
|
||||||
callback_api = getattr(mqtt, "CallbackAPIVersion", None)
|
callback_api = getattr(mqtt, "CallbackAPIVersion", None)
|
||||||
|
|
||||||
if callback_api is not None:
|
if callback_api is not None:
|
||||||
mqttc = mqtt.Client("birdnet_mqtt", callback_api_version=callback_api.VERSION1)
|
# paho-mqtt >= 2.0: first argument is callback_api_version
|
||||||
|
mqttc = mqtt.Client(callback_api.VERSION1, client_id="birdnet_mqtt")
|
||||||
else:
|
else:
|
||||||
mqttc = mqtt.Client("birdnet_mqtt")
|
# paho-mqtt < 2.0: old signature, first argument is client_id
|
||||||
|
mqttc = mqtt.Client(client_id="birdnet_mqtt")
|
||||||
|
|
||||||
mqttc.username_pw_set(mqtt_user, mqtt_pass)
|
mqttc.username_pw_set(mqtt_user, mqtt_pass)
|
||||||
mqttc.on_connect = on_connect
|
mqttc.on_connect = on_connect
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user