MqttMonitor/MqttMonitorWidget.py

branch
eric7
changeset 105
36ec7431ad04
parent 104
9a4c9b7f078c
child 106
84498095d511
--- a/MqttMonitor/MqttMonitorWidget.py	Fri Jul 23 17:48:22 2021 +0200
+++ b/MqttMonitor/MqttMonitorWidget.py	Fri Jul 23 19:48:14 2021 +0200
@@ -22,10 +22,10 @@
 from .Ui_MqttMonitorWidget import Ui_MqttMonitorWidget
 
 from .MqttClient import (
-    MqttClient, MqttProtocols, mqttConnackMessage, mqttErrorMessage,
-    mqttLogLevelString
+    MqttClient, mqttConnackMessage, mqttErrorMessage, mqttLogLevelString
 )
 from .MqttReasonCodes import mqttReasonCode
+from .MqttProtocols import MqttProtocols
 
 import UI.PixmapCache
 import Utilities
@@ -214,10 +214,8 @@
         self.__statusLoadValues = collections.defaultdict(
             self.__loadDefaultDictFactory)
     
-    # TODO: make MQTT default protocol version a configuration option
-    # (config page)
     def __createClient(self, clientId="", cleanSession=None,
-                       protocol=MqttProtocols.MQTTv311):
+                       protocol=None):
         """
         Private method to instantiate a MQTT client for a given protocol.
         
@@ -225,12 +223,14 @@
         @type str
         @param cleanSession flag indicating to start a clean session
         @type bool
-        @param protocol MQTT protocol version to be used (defaults to
-            MqttProtocols.MQTTv311)
-        @type MqttProtocols (optional)
+        @param protocol MQTT protocol version to be used (defaults to None)
+        @type MqttProtocols or int (optional)
         @return created and connected MQTT client object
         @rtype MqttClient
         """
+        if protocol is None:
+            protocol = self.__plugin.getPreferences("DefaultProtocol")
+        
         client = MqttClient(clientId=clientId, cleanSession=cleanSession,
                             protocol=protocol)
         
@@ -1342,7 +1342,8 @@
             try:
                 protocol = connectionProfile["Protocol"]
             except KeyError:
-                protocol = MqttProtocols.MQTTv311
+                protocol = MqttProtocols(
+                    self.__plugin.getPreferences("DefaultProtocol"))
             
             self.brokerStatusLabel.setText(
                 self.tr("Connecting to {0}:{1} ...").format(

eric ide

mercurial