Sholofly / lghorizon-python

Api for controlling LG Horizon settop boxes
MIT License
1 stars 6 forks source link

MQTT connection failing #39

Open AndrewKlopper opened 2 weeks ago

AndrewKlopper commented 2 weeks ago

I installed the library using pip install lghorizon, which installs paho_mqtt-2.1.0 due to the requirement paho-mqtt>=1.5.0. Unfortunately, paho-mqtt version 2 introduced some breaking changes. Running the test.py script results in the following error after authentication when trying to connect to a Ziggo NL account:

2024-08-26 17:06:56,098 - INFO - Backing off connect(...) for 2.0s (ValueError: Unsupported callback API version: version 2.0 added a callback_api_version, see docs/migrations.rst for details)
Backing off connect(...) for 2.0s (ValueError: Unsupported callback API version: version 2.0 added a callback_api_version, see docs/migrations.rst for details)

This can be fixed with the following modification to the models.py file:

--- models.py.orig      2024-08-26 17:05:58.675362315 +0200
+++ models.py   2024-08-26 17:06:04.335404067 +0200
@@ -335,7 +335,7 @@
         self._auth = auth
         self._brokerUrl = mqtt_broker_url.replace("wss://", "").replace(":443/mqtt", "")
         self.clientId = make_id()
-        self._mqtt_client = mqtt.Client(self.clientId, transport="websockets")
+        self._mqtt_client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1, self.clientId, transport="websockets")

         self._mqtt_client.ws_set_options(
             headers={"Sec-WebSocket-Protocol": "mqtt, mqttv3.1, mqttv3.11"}
AndrewKlopper commented 2 weeks ago

I have worked around this issue using the following requirements.txt file for my project:

lghorizon
paho-mqtt<2.0.0