Skip to content

Commit

Permalink
Support paho_mqtt >= 2, fixes jziolkowski#267
Browse files Browse the repository at this point in the history
  • Loading branch information
RichieB2B committed Oct 29, 2024
1 parent a1923da commit 92f96c6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
paho_mqtt>=1.4,<2
paho_mqtt>=1.4
PyQt5>=5.14.2,<6
pydantic==2.5.2
16 changes: 12 additions & 4 deletions tdmgr/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class MqttClient(QObject):

MQTT_3_1 = mqtt.MQTTv31
MQTT_3_1_1 = mqtt.MQTTv311
MQTT_5 = mqtt.MQTTv5

connected = pyqtSignal()
connecting = pyqtSignal()
Expand Down Expand Up @@ -143,9 +144,16 @@ def __init__(self, parent=None):

self.m_state = MqttClient.Disconnected

self.m_client = mqtt.Client(
clean_session=self.m_cleanSession, protocol=self.protocolVersion
)
if hasattr(mqtt, 'CallbackAPIVersion'):
self.m_protocolVersion = MqttClient.MQTT_5
self.m_client = mqtt.Client(
callback_api_version=mqtt.CallbackAPIVersion.VERSION2, protocol=self.protocolVersion
)
else:
self.m_protocolVersion = MqttClient.MQTT_3_1
self.m_client = mqtt.Client(
clean_session=self.m_cleanSession, protocol=self.protocolVersion
)

self.m_client.on_connect = self.on_connect
self.m_client.on_message = self.on_message
Expand Down Expand Up @@ -217,7 +225,7 @@ def protocolVersion(self):
def protocolVersion(self, protocolVersion):
if self.m_protocolVersion == protocolVersion:
return
if protocolVersion in (MqttClient.MQTT_3_1, MqttClient.MQTT_3_1_1):
if protocolVersion in (MqttClient.MQTT_3_1, MqttClient.MQTT_3_1_1, MqttClient.MQTT_5):
self.m_protocolVersion = protocolVersion
self.protocolVersionChanged.emit(protocolVersion)

Expand Down

0 comments on commit 92f96c6

Please sign in to comment.