Improve MQTT failed connection error message (#13184)

This commit is contained in:
Otto Winter 2018-03-13 21:56:16 +01:00 committed by Paulus Schoutsen
parent 3e7a737bff
commit 5958e6a60f

View File

@ -515,16 +515,20 @@ class MQTT(object):
This method is a coroutine.
"""
result = None # type: int
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):