Improve MQTT failed connection error message (#13184)
This commit is contained in:
1 parent
3e7a737bff
commit
5958e6a60f
1 file changed
+9
-5
@@ -515,16 +515,20 @@ class MQTT(object):
|
||||
This method is a coroutine.
|
||||
"""
|
||||
result = None # type: int
|
||||
result = await self.hass.async_add_job(
|
||||
self._mqttc.connect, self.broker, self.port, self.keepalive)
|
||||
try:
|
||||
result = await self.hass.async_add_job(
|
||||
self._mqttc.connect, self.broker, self.port, self.keepalive)
|
||||
except OSError as err:
|
||||
_LOGGER.error('Failed to connect due to exception: %s', err)
|
||||
return False
|
||||
|
||||
if result != 0:
|
||||
import paho.mqtt.client as mqtt
|
||||
_LOGGER.error('Failed to connect: %s', mqtt.error_string(result))
|
||||
else:
|
||||
self._mqttc.loop_start()
|
||||
return False
|
||||
|
||||
return not result
|
||||
self._mqttc.loop_start()
|
||||
return True
|
||||
|
||||
@callback
|
||||
def async_disconnect(self):
|
||||
|
||||
Reference in new issue
Block a user