diff --git a/CHANGELOG.md b/CHANGELOG.md index 893d808..0ed233f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## v3.0.13 + +- Fix missing webrtc initialization led for camera component to fail loading +- Removed first time loading by outdated function, instead use request to refresh data after loading is done (to avoid waiting for next iteration in 30 seconds) +- Fix stability of WebSocket connection + ## v3.0.12 - Fix errors introduced in v3.0.11 while trying to get results from API diff --git a/custom_components/shinobi/camera.py b/custom_components/shinobi/camera.py index 8b1e37f..06c36ea 100644 --- a/custom_components/shinobi/camera.py +++ b/custom_components/shinobi/camera.py @@ -58,6 +58,8 @@ def __init__( ): super().__init__(hass, entity_description, coordinator, monitor) + Camera.__init__(self) + self.stream: Stream | None = None self.stream_options: dict[str, str | bool | float] = {} self.content_type: str = DEFAULT_CONTENT_TYPE @@ -65,7 +67,7 @@ def __init__( self._warned_old_signature = False self.async_update_token() self._create_stream_lock: asyncio.Lock | None = None - self._rtsp_to_webrtc = False + self._rtsp_to_webrtc = True self._stream_source = None diff --git a/custom_components/shinobi/managers/coordinator.py b/custom_components/shinobi/managers/coordinator.py index 20b8bcb..48bf045 100644 --- a/custom_components/shinobi/managers/coordinator.py +++ b/custom_components/shinobi/managers/coordinator.py @@ -39,7 +39,6 @@ DATA_KEY_SOUND_DETECTION, DEFAULT_NAME, DOMAIN, - HEARTBEAT_INTERVAL, SIGNAL_API_STATUS, SIGNAL_MONITOR_ADDED, SIGNAL_MONITOR_DISCOVERED, @@ -90,6 +89,7 @@ def __init__(self, hass, config_manager: ConfigManager): name=config_manager.entry_title, update_interval=UPDATE_ENTITIES_INTERVAL, update_method=self._async_update_data, + config_entry=config_manager.entry, ) self._api = RestAPI(hass, config_manager) @@ -192,16 +192,17 @@ def on_ws_ready(entry_id: str): ) async def initialize(self): - self._build_data_mapping() - entry = self.config_manager.entry - await self.hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) _LOGGER.info(f"Start loading {DOMAIN} integration, Entry ID: {entry.entry_id}") + self._build_data_mapping() + + await self.hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) + views_async_setup(self.hass, self._config_manager) - await self.async_config_entry_first_refresh() + await self.async_request_refresh() await self._api.initialize() @@ -379,11 +380,6 @@ async def _async_update_data(self): if is_ready: now = datetime.now().timestamp() - if now - self._last_heartbeat >= HEARTBEAT_INTERVAL.total_seconds(): - await self._websockets.send_heartbeat() - - self._last_heartbeat = now - if now - self._last_update >= UPDATE_API_INTERVAL.total_seconds(): await self._api.update() diff --git a/custom_components/shinobi/managers/websockets.py b/custom_components/shinobi/managers/websockets.py index 5dee657..38406ae 100644 --- a/custom_components/shinobi/managers/websockets.py +++ b/custom_components/shinobi/managers/websockets.py @@ -36,7 +36,6 @@ 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, @@ -247,23 +246,6 @@ async def _initialize_session(self): self._set_status(ConnectivityStatus.Failed) - async def send_heartbeat(self): - if self._session is None or self._session.closed: - self._set_status(ConnectivityStatus.NotConnected) - - if self.status == ConnectivityStatus.Connected: - try: - await self._ws.ping(SHINOBI_WS_PING_MESSAGE) - - except ConnectionResetError as crex: - _LOGGER.debug( - f"Gracefully failed to send heartbeat - Restarting connection, Error: {crex}" - ) - self._set_status(ConnectivityStatus.NotConnected) - - except Exception as ex: - _LOGGER.error(f"Failed to send heartbeat, Error: {ex}") - async def _listen(self): _LOGGER.info("Starting to listen connected") @@ -377,6 +359,7 @@ async def _handle_action_message(self, prefix, data): _LOGGER.debug(f"Payload ({prefix}) received, Type: {func}") elif action == WS_EVENT_ACTION_PING: + _LOGGER.debug("Ping received") await self._send_pong_message(data) else: @@ -499,6 +482,8 @@ async def _send_pong_message(self, data): json_str = json.dumps(message_data) message = f"42{json_str}" + _LOGGER.debug("Pong sent") + await self._send(message) async def send_connect_monitor(self, monitor_id: str): diff --git a/custom_components/shinobi/manifest.json b/custom_components/shinobi/manifest.json index 908ff7a..5930f83 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.12" + "version": "3.0.13" }