From 431a8d0047dd22f1c40a97db72cbf23efb844344 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Mon, 13 Mar 2023 12:16:52 +0100 Subject: [PATCH] Add support for dual lens cameras in Reolink (#89554) --- homeassistant/components/reolink/camera.py | 9 +++++++-- homeassistant/components/reolink/entity.py | 12 +++++++++--- homeassistant/components/reolink/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/reolink/camera.py b/homeassistant/components/reolink/camera.py index 13471df3392..a34f8c85d36 100644 --- a/homeassistant/components/reolink/camera.py +++ b/homeassistant/components/reolink/camera.py @@ -3,6 +3,8 @@ from __future__ import annotations import logging +from reolink_aio.api import DUAL_LENS_MODELS + from homeassistant.components.camera import Camera, CameraEntityFeature from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant @@ -25,7 +27,7 @@ async def async_setup_entry( host = reolink_data.host cameras = [] - for channel in host.api.channels: + for channel in host.api.stream_channels: streams = ["sub", "main", "snapshots"] if host.api.protocol in ["rtmp", "flv"]: streams.append("ext") @@ -56,7 +58,10 @@ class ReolinkCamera(ReolinkChannelCoordinatorEntity, Camera): self._stream = stream - self._attr_name = self._stream + if self._host.api.model in DUAL_LENS_MODELS: + self._attr_name = f"{self._stream} 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" diff --git a/homeassistant/components/reolink/entity.py b/homeassistant/components/reolink/entity.py index 3a962d099df..48652eac21a 100644 --- a/homeassistant/components/reolink/entity.py +++ b/homeassistant/components/reolink/entity.py @@ -3,6 +3,8 @@ from __future__ import annotations from typing import TypeVar +from reolink_aio.api import DUAL_LENS_MODELS + from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.update_coordinator import ( @@ -75,12 +77,16 @@ class ReolinkChannelCoordinatorEntity(ReolinkHostCoordinatorEntity): self._channel = channel + dev_ch = channel + if self._host.api.model in DUAL_LENS_MODELS: + dev_ch = 0 + if self._host.api.is_nvr: self._attr_device_info = DeviceInfo( - identifiers={(DOMAIN, f"{self._host.unique_id}_ch{self._channel}")}, + identifiers={(DOMAIN, f"{self._host.unique_id}_ch{dev_ch}")}, via_device=(DOMAIN, self._host.unique_id), - name=self._host.api.camera_name(self._channel), - model=self._host.api.camera_model(self._channel), + name=self._host.api.camera_name(dev_ch), + model=self._host.api.camera_model(dev_ch), manufacturer=self._host.api.manufacturer, configuration_url=self._conf_url, ) diff --git a/homeassistant/components/reolink/manifest.json b/homeassistant/components/reolink/manifest.json index 5cb7530ec8e..35ce21ab782 100644 --- a/homeassistant/components/reolink/manifest.json +++ b/homeassistant/components/reolink/manifest.json @@ -18,5 +18,5 @@ "documentation": "https://www.home-assistant.io/integrations/reolink", "iot_class": "local_push", "loggers": ["reolink_aio"], - "requirements": ["reolink-aio==0.5.3"] + "requirements": ["reolink-aio==0.5.4"] } diff --git a/requirements_all.txt b/requirements_all.txt index 1a19b090723..478db405697 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2237,7 +2237,7 @@ regenmaschine==2022.11.0 renault-api==0.1.12 # homeassistant.components.reolink -reolink-aio==0.5.3 +reolink-aio==0.5.4 # homeassistant.components.python_script restrictedpython==6.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 685653627e2..9122d05933a 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1594,7 +1594,7 @@ regenmaschine==2022.11.0 renault-api==0.1.12 # homeassistant.components.reolink -reolink-aio==0.5.3 +reolink-aio==0.5.4 # homeassistant.components.python_script restrictedpython==6.0