Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support paho_mqtt >= 2, fixes #267 #300

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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