diff --git a/homeassistant/components/reolink/camera.py b/homeassistant/components/reolink/camera.py index fe8843628088..2e5d740fd21e 100644 --- a/homeassistant/components/reolink/camera.py +++ b/homeassistant/components/reolink/camera.py @@ -1,10 +1,13 @@ """Component providing support for Reolink IP cameras.""" +from collections.abc import Callable from dataclasses import dataclass from datetime import datetime import logging from typing import override +from reolink_aio.api import Host + from homeassistant.components.camera import ( Camera, CameraEntityCapabilities, @@ -31,6 +34,7 @@ class ReolinkCameraEntityDescription( """A class that describes camera entities for a camera channel.""" stream: str + enabled_default: Callable[[Host, int], bool] | None = None # a camera stream always comes from a single lens lens_entity: bool = True @@ -48,28 +52,30 @@ CAMERA_ENTITIES = ( key="main", stream="main", translation_key="main", + enabled_default=lambda api, ch: not api.supported(ch, "sub"), supported=lambda api, ch: ( api.supported(ch, "stream") and api.supported(ch, "main") ), - entity_registry_enabled_default=False, ), ReolinkCameraEntityDescription( key="snapshots_sub", stream="snapshots_sub", translation_key="snapshots_sub", + enabled_default=lambda api, ch: not api.supported(ch, "stream"), supported=lambda api, ch: ( api.supported(ch, "snapshot") and api.supported(ch, "sub") ), - entity_registry_enabled_default=False, ), ReolinkCameraEntityDescription( key="snapshots", stream="snapshots_main", translation_key="snapshots_main", + enabled_default=lambda api, ch: ( + not api.supported(ch, "stream") and not api.supported(ch, "sub") + ), supported=lambda api, ch: ( api.supported(ch, "snapshot") and api.supported(ch, "main") ), - entity_registry_enabled_default=False, ), ReolinkCameraEntityDescription( key="ext", @@ -90,28 +96,30 @@ CAMERA_ENTITIES = ( key="autotrack_main", stream="telephoto_main", translation_key="telephoto_main", + enabled_default=lambda api, ch: not api.supported(ch, "sub"), supported=lambda api, ch: ( api.supported(ch, "autotrack_stream") and api.supported(ch, "main") ), - entity_registry_enabled_default=False, ), ReolinkCameraEntityDescription( key="autotrack_snapshots_sub", stream="autotrack_snapshots_sub", translation_key="telephoto_snapshots_sub", + enabled_default=lambda api, ch: not api.supported(ch, "stream"), supported=lambda api, ch: ( api.supported(ch, "autotrack_snapshot") and api.supported(ch, "sub") ), - entity_registry_enabled_default=False, ), ReolinkCameraEntityDescription( key="autotrack_snapshots_main", stream="autotrack_snapshots_main", translation_key="telephoto_snapshots_main", + enabled_default=lambda api, ch: ( + not api.supported(ch, "stream") and not api.supported(ch, "sub") + ), supported=lambda api, ch: ( api.supported(ch, "autotrack_snapshot") and api.supported(ch, "main") ), - entity_registry_enabled_default=False, ), ) @@ -165,6 +173,11 @@ class ReolinkCamera(ReolinkChannelCoordinatorEntity, Camera): ) ) + if entity_description.enabled_default is not None: + self._attr_entity_registry_enabled_default = ( + entity_description.enabled_default(self._host.api, self._channel) + ) + if self._host.api.is_dual_lens: self._attr_translation_key = ( f"{entity_description.translation_key}_lens_{self._channel}"