diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index 87acbc7..f58ae94 100644 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -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: diff --git a/src/mqtt.py b/src/mqtt.py index 1b7d8b3..4883b2b 100644 --- a/src/mqtt.py +++ b/src/mqtt.py @@ -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")