mirror of
https://github.com/Dielee/volvo2mqtt.git
synced 2026-07-22 02:13:01 +02:00
Fix AttributeError for paho-mqtt < 2.0 compatibility (#321)
When paho-mqtt < 2.0 is installed (e.g. in cached Docker layers), mqtt.CallbackAPIVersion does not exist, causing an immediate crash on startup with: AttributeError: module 'paho.mqtt.client' has no attribute 'CallbackAPIVersion' Add try/except fallback so the addon works with both paho-mqtt 1.x and 2.x, eliminating the crash and allowing the addon to start correctly. Co-authored-by: Barry Jarman <bazza@Barrys-Mac-mini.local> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
co-authored by
Barry Jarman
Copilot
parent
76cfa21db7
commit
48663d2e0d
@@ -1,3 +1,9 @@
|
||||
## v1.13.4
|
||||
|
||||
### 🐛 Bug Fixes:
|
||||
|
||||
- Fix `AttributeError: module 'paho.mqtt.client' has no attribute 'CallbackAPIVersion'` when paho-mqtt < 2.0 is installed
|
||||
|
||||
## v1.13.3
|
||||
|
||||
### 🐛 Bug Fixes:
|
||||
|
||||
+7
-3
@@ -25,9 +25,13 @@ active_schedules = {}
|
||||
otp_code = None
|
||||
|
||||
def connect():
|
||||
client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1, "volvoAAOS2mqtt") \
|
||||
if os.environ.get("IS_HA_ADDON") \
|
||||
else mqtt.Client(mqtt.CallbackAPIVersion.VERSION1, "volvoAAOS2mqtt_" + settings.volvoData["username"].replace("+", ""))
|
||||
client_id = "volvoAAOS2mqtt" if os.environ.get("IS_HA_ADDON") \
|
||||
else "volvoAAOS2mqtt_" + settings.volvoData["username"].replace("+", "")
|
||||
try:
|
||||
client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1, client_id)
|
||||
except AttributeError:
|
||||
# paho-mqtt < 2.0 does not have CallbackAPIVersion
|
||||
client = mqtt.Client(client_id)
|
||||
|
||||
if "logging" in settings["mqtt"] and settings["mqtt"]["logging"]:
|
||||
mqtt_logger = logging.getLogger("mqtt")
|
||||
|
||||
Reference in New Issue
Block a user