Add log to show last received UniFi websocket message (#109167)

This commit is contained in:
Robert Svensson 2024-01-31 08:46:47 +01:00 committed by GitHub
parent 9ed50d8b0c
commit 30fdb2a8b3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 20 additions and 3 deletions

View file

@ -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

View file

@ -8,7 +8,7 @@
"iot_class": "local_push",
"loggers": ["aiounifi"],
"quality_scale": "platinum",
"requirements": ["aiounifi==69"],
"requirements": ["aiounifi==70"],
"ssdp": [
{
"manufacturer": "Ubiquiti Networks",

View file

@ -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

View file

@ -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