@@ -195,8 +195,8 @@ def get_host_model():
195195 model = f'{ deviceManufacturer } { deviceNameDisplay } '
196196 return model
197197
198- def on_connect (client , userdata , flags , rc ):
199- if rc == 0 :
198+ def on_connect (client , userdata , flags , reason_code , properties ):
199+ if reason_code == 0 :
200200 write_message_to_console ('Connected to broker' )
201201 print ("subscribing : " + f"{ ha_status } /status" )
202202 client .subscribe (f"{ ha_status } /status" )
@@ -205,7 +205,7 @@ def on_connect(client, userdata, flags, rc):
205205 print ("subscribing : " + f"system-sensors/sensor/{ devicename } /command" )
206206 client .subscribe (f"system-sensors/sensor/{ devicename } /command" )#subscribe
207207 client .publish (f"system-sensors/sensor/{ devicename } /command" , "setup" , retain = True )
208- elif rc == 5 :
208+ elif reason_code == 'Bad user name or password' :
209209 write_message_to_console ('Authentication failed.\n Exiting.' )
210210 sys .exit ()
211211 else :
@@ -265,7 +265,7 @@ def on_message(client, userdata, message):
265265 else :
266266 # for paho 2.x clients
267267 # note that a deprecation warning gets logged
268- mqttClient = mqtt .Client (mqtt .CallbackAPIVersion .VERSION1 , client_id = settings ['client_id' ])
268+ mqttClient = mqtt .Client (mqtt .CallbackAPIVersion .VERSION2 , client_id = settings ['client_id' ])
269269
270270 mqttClient .on_connect = on_connect #attach function to callback
271271 mqttClient .on_message = on_message
0 commit comments