From b91c6911d9fde75c9309157e44dba28ec7eedff3 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Wed, 31 May 2023 03:42:58 +0200 Subject: [PATCH] Reolink autotrack streams for TrackMix and high/low resolution snapshots (#90591) * Add auto track stream for Trackmix connected to NVR * Enable autotracking stream by default * Add snapshot high/low resolution * Improve naming * fix snapshots camera's not beeing added * keep unique ID the same * fix styling --- homeassistant/components/reolink/camera.py | 23 +++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/reolink/camera.py b/homeassistant/components/reolink/camera.py index a34f8c85d36..b012649ec4c 100644 --- a/homeassistant/components/reolink/camera.py +++ b/homeassistant/components/reolink/camera.py @@ -28,13 +28,18 @@ async def async_setup_entry( cameras = [] for channel in host.api.stream_channels: - streams = ["sub", "main", "snapshots"] + streams = ["sub", "main", "snapshots_sub", "snapshots_main"] if host.api.protocol in ["rtmp", "flv"]: streams.append("ext") + if host.api.supported(channel, "autotrack_stream"): + streams.extend( + ["autotrack_sub", "autotrack_snapshots_sub", "autotrack_snapshots_main"] + ) + for stream in streams: stream_url = await host.api.get_stream_source(channel, stream) - if stream_url is None and stream != "snapshots": + if stream_url is None and "snapshots" not in stream: continue cameras.append(ReolinkCamera(reolink_data, channel, stream)) @@ -58,12 +63,16 @@ class ReolinkCamera(ReolinkChannelCoordinatorEntity, Camera): self._stream = stream + stream_name = self._stream.replace("_", " ") if self._host.api.model in DUAL_LENS_MODELS: - self._attr_name = f"{self._stream} lens {self._channel}" + self._attr_name = f"{stream_name} lens {self._channel}" else: - self._attr_name = self._stream - self._attr_unique_id = f"{self._host.unique_id}_{self._channel}_{self._stream}" - self._attr_entity_registry_enabled_default = stream == "sub" + self._attr_name = stream_name + stream_id = self._stream + if stream_id == "snapshots_main": + stream_id = "snapshots" + self._attr_unique_id = f"{self._host.unique_id}_{self._channel}_{stream_id}" + self._attr_entity_registry_enabled_default = stream in ["sub", "autotrack_sub"] async def stream_source(self) -> str | None: """Return the source of the stream.""" @@ -73,4 +82,4 @@ class ReolinkCamera(ReolinkChannelCoordinatorEntity, Camera): self, width: int | None = None, height: int | None = None ) -> bytes | None: """Return a still image response from the camera.""" - return await self._host.api.get_snapshot(self._channel) + return await self._host.api.get_snapshot(self._channel, self._stream)