diff --git a/homeassistant/components/unifi/controller.py b/homeassistant/components/unifi/controller.py index de97631c036..eb127a5dfd9 100644 --- a/homeassistant/components/unifi/controller.py +++ b/homeassistant/components/unifi/controller.py @@ -75,6 +75,7 @@ from .errors import AuthenticationRequired, CannotConnect RETRY_TIMER = 15 CHECK_HEARTBEAT_INTERVAL = timedelta(seconds=1) +CHECK_WEBSOCKET_INTERVAL = timedelta(minutes=1) class UniFiController: @@ -89,6 +90,7 @@ class UniFiController: self.api = api self.ws_task: asyncio.Task | None = None + self._cancel_websocket_check: CALLBACK_TYPE | None = None self.available = True self.wireless_clients = hass.data[UNIFI_WIRELESS_CLIENTS] @@ -275,6 +277,9 @@ class UniFiController: self._cancel_heartbeat_check = async_track_time_interval( self.hass, self._async_check_for_stale, CHECK_HEARTBEAT_INTERVAL ) + self._cancel_websocket_check = async_track_time_interval( + self.hass, self._async_watch_websocket, CHECK_WEBSOCKET_INTERVAL + ) @callback def async_heartbeat( @@ -411,6 +416,14 @@ class UniFiController: ): self.hass.loop.call_later(RETRY_TIMER, self.reconnect) + @callback + def _async_watch_websocket(self, now: datetime) -> None: + """Watch timestamp for last received websocket message.""" + LOGGER.debug( + "Last received websocket timestamp: %s", + self.api.connectivity.ws_message_received, + ) + @callback def shutdown(self, event: Event) -> None: """Wrap the call to unifi.close. @@ -450,6 +463,10 @@ class UniFiController: self._cancel_heartbeat_check() self._cancel_heartbeat_check = None + if self._cancel_websocket_check: + self._cancel_websocket_check() + self._cancel_websocket_check = None + if self._cancel_poe_command: self._cancel_poe_command() self._cancel_poe_command = None diff --git a/homeassistant/components/unifi/manifest.json b/homeassistant/components/unifi/manifest.json index 90b4421f164..f69dffc2d57 100644 --- a/homeassistant/components/unifi/manifest.json +++ b/homeassistant/components/unifi/manifest.json @@ -8,7 +8,7 @@ "iot_class": "local_push", "loggers": ["aiounifi"], "quality_scale": "platinum", - "requirements": ["aiounifi==69"], + "requirements": ["aiounifi==70"], "ssdp": [ { "manufacturer": "Ubiquiti Networks", diff --git a/requirements_all.txt b/requirements_all.txt index 811438841aa..11ad645c36f 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -380,7 +380,7 @@ aiosyncthing==0.5.1 aiotractive==0.5.6 # homeassistant.components.unifi -aiounifi==69 +aiounifi==70 # homeassistant.components.vlc_telnet aiovlc==0.1.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index b691ded8376..a107f1d2a88 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -353,7 +353,7 @@ aiosyncthing==0.5.1 aiotractive==0.5.6 # homeassistant.components.unifi -aiounifi==69 +aiounifi==70 # homeassistant.components.vlc_telnet aiovlc==0.1.0