@@ -22,10 +22,7 @@ def __init__(self, sensor_service, config=None):
22
22
self ._client = None
23
23
self ._hostname = self ._config .get ('hostname' , None )
24
24
self ._port = self ._config .get ('port' , 1883 )
25
- # NOTE: Need to translate MQTT* names into values expected by paho
26
- # Default to MQTTv311 if value is not valid since we can't
27
- # enforce "allowed" values from the pack config schema
28
- self ._protocol = getattr (mqtt , self ._config .get ('protocol' , '' ), mqtt .MQTTv311 )
25
+ self ._protocol = self ._config .get ('protocol' , 'MQTTv311' )
29
26
self ._client_id = self ._config .get ('client_id' , None )
30
27
self ._userdata = self ._config .get ('userdata' , None )
31
28
self ._username = self ._config .get ('username' , None )
@@ -39,8 +36,11 @@ def __init__(self, sensor_service, config=None):
39
36
def setup (self ):
40
37
self ._logger .debug ('[MQTTSensor]: setting up sensor...' )
41
38
39
+ # NOTE: Need to ensure `protocol` MQTT* names are properly
40
+ # handled as paho.mqtt constants and not bare strings
42
41
self ._client = mqtt .Client (self ._client_id , clean_session = True ,
43
- userdata = self ._userdata , protocol = self ._protocol )
42
+ userdata = self ._userdata ,
43
+ protocol = getattr (mqtt , self ._protocol ))
44
44
45
45
if self ._username :
46
46
self ._client .username_pw_set (self ._username , password = self ._password )
0 commit comments