diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ed233f..bc9f90f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v3.0.14 + +- Corrected keep alive process to fix motion and sound detection - [Issue #77](https://github.com/elad-bar/ha-shinobi/issues/77) + ## v3.0.13 - Fix missing webrtc initialization led for camera component to fail loading diff --git a/custom_components/shinobi/managers/coordinator.py b/custom_components/shinobi/managers/coordinator.py index 48bf045..762a2f0 100644 --- a/custom_components/shinobi/managers/coordinator.py +++ b/custom_components/shinobi/managers/coordinator.py @@ -137,19 +137,19 @@ def _load_signal_handlers(self): @callback def on_api_status_changed(entry_id: str, status: ConnectivityStatus): - loop.create_task(self._on_api_status_changed(entry_id, status)).__await__() + loop.create_task(self._on_api_status_changed(entry_id, status)) @callback def on_ws_status_changed(entry_id: str, status: ConnectivityStatus): - loop.create_task(self._on_ws_status_changed(entry_id, status)).__await__() + loop.create_task(self._on_ws_status_changed(entry_id, status)) @callback def on_monitor_discovered(entry_id: str, monitor: MonitorData): - loop.create_task(self._on_monitor_discovered(entry_id, monitor)).__await__() + loop.create_task(self._on_monitor_discovered(entry_id, monitor)) @callback def on_monitor_updated(entry_id: str, monitor: MonitorData): - loop.create_task(self._on_monitor_updated(entry_id, monitor)).__await__() + loop.create_task(self._on_monitor_updated(entry_id, monitor)) @callback def on_monitor_triggered( @@ -157,21 +157,21 @@ def on_monitor_triggered( ): loop.create_task( self._on_monitor_triggered(entry_id, monitor_id, event_type, value) - ).__await__() + ) @callback def on_monitor_status_changed(entry_id: str, monitor_id: str, status_code: int): loop.create_task( self._on_monitor_status_changed(entry_id, monitor_id, status_code) - ).__await__() + ) @callback def on_server_discovered(entry_id: str): - loop.create_task(self._on_server_discovered(entry_id)).__await__() + loop.create_task(self._on_server_discovered(entry_id)) @callback def on_ws_ready(entry_id: str): - loop.create_task(self._on_ws_ready(entry_id)).__await__() + loop.create_task(self._on_ws_ready(entry_id)) signal_handlers = { SIGNAL_API_STATUS: on_api_status_changed, diff --git a/custom_components/shinobi/managers/websockets.py b/custom_components/shinobi/managers/websockets.py index 38406ae..9fc3704 100644 --- a/custom_components/shinobi/managers/websockets.py +++ b/custom_components/shinobi/managers/websockets.py @@ -36,6 +36,7 @@ SHINOBI_WS_CONNECTION_ESTABLISHED_MESSAGE, SHINOBI_WS_CONNECTION_READY_MESSAGE, SHINOBI_WS_ENDPOINT, + SHINOBI_WS_PING_MESSAGE, SHINOBI_WS_PONG_MESSAGE, SIGNAL_MONITOR_STATUS_CHANGED, SIGNAL_MONITOR_TRIGGER, @@ -99,7 +100,7 @@ def __init__( self._messages_handler: dict = { SHINOBI_WS_CONNECTION_ESTABLISHED_MESSAGE: self._handle_connection_established_message, - SHINOBI_WS_PONG_MESSAGE: self._handle_pong_message, + SHINOBI_WS_PING_MESSAGE: self._handle_ping_message, SHINOBI_WS_CONNECTION_READY_MESSAGE: self._handle_ready_state_message, SHINOBI_WS_ACTION_MESSAGE: self._handle_action_message, } @@ -195,8 +196,14 @@ async def initialize(self): self._set_status(ConnectivityStatus.Connected) self._ws = ws + await self._listen() + if self.status != ConnectivityStatus.Connected: + _LOGGER.warning( + f"Stopped listening to web socket, Status: {self.status}" + ) + except Exception as ex: exc_type, exc_obj, tb = sys.exc_info() line_number = tb.tb_lineno @@ -320,9 +327,10 @@ async def _handle_connection_established_message(self, prefix, data): if self.version == 4: await self._send(SHINOBI_WS_CONNECTION_READY_MESSAGE) - @staticmethod - async def _handle_pong_message(prefix, data): - _LOGGER.debug(f"Pong message received, ID: {prefix}, Payload: {data}") + async def _handle_ping_message(self, prefix, data): + _LOGGER.debug(f"Ping message received, ID: {prefix}, Payload: {data}") + + await self._send(SHINOBI_WS_PONG_MESSAGE) async def _handle_ready_state_message(self, prefix, data): _LOGGER.debug( @@ -628,8 +636,8 @@ def _set_status(self, status: ConnectivityStatus): status, ) - def set_local_async_dispatcher_send(self, callback): - self._local_async_dispatcher_send = callback + def set_local_async_dispatcher_send(self, cb): + self._local_async_dispatcher_send = cb def _async_dispatcher_send(self, signal: str, *args: Any) -> None: if self._hass is None: diff --git a/custom_components/shinobi/manifest.json b/custom_components/shinobi/manifest.json index 5930f83..26b3b38 100644 --- a/custom_components/shinobi/manifest.json +++ b/custom_components/shinobi/manifest.json @@ -9,5 +9,5 @@ "iot_class": "local_polling", "issue_tracker": "https://github.com/elad-bar/ha-shinobi/issues", "requirements": [], - "version": "3.0.13" + "version": "3.0.14" }