UniFi - Improve logging related to loosing connection to controller (#34547)

pull/34572/head
Robert Svensson 2020-04-22 20:45:09 +02:00 committed by GitHub
parent dcf51e5a14
commit 224c874673
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 4 deletions

View File

@ -174,7 +174,7 @@ class UniFiController:
if signal == SIGNAL_CONNECTION_STATE:
if data == STATE_DISCONNECTED and self.available:
LOGGER.error("Lost connection to UniFi")
LOGGER.warning("Lost connection to UniFi controller")
if (data == STATE_RUNNING and not self.available) or (
data == STATE_DISCONNECTED and self.available
@ -183,7 +183,9 @@ class UniFiController:
async_dispatcher_send(self.hass, self.signal_reachable)
if not self.available:
self.hass.loop.call_later(RETRY_TIMER, self.reconnect)
self.hass.loop.call_later(RETRY_TIMER, self.reconnect, True)
else:
LOGGER.info("Connected to UniFi controller")
elif signal == SIGNAL_DATA and data:
@ -292,9 +294,10 @@ class UniFiController:
async_dispatcher_send(hass, controller.signal_options_update)
@callback
def reconnect(self) -> None:
def reconnect(self, log=False) -> None:
"""Prepare to reconnect UniFi session."""
LOGGER.debug("Reconnecting to UniFi in %i", RETRY_TIMER)
if log:
LOGGER.info("Will try to reconnect to UniFi controller")
self.hass.loop.create_task(self.async_reconnect())
async def async_reconnect(self) -> None: