From 40127a5ca4fb8b1b15c2b274df77d0251f7d83d8 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Sun, 26 Jan 2025 20:03:13 +0100 Subject: [PATCH] Add Reolink privacy switch entity (#136521) --- homeassistant/components/reolink/icons.json | 6 +++++ homeassistant/components/reolink/strings.json | 3 +++ homeassistant/components/reolink/switch.py | 26 +++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/homeassistant/components/reolink/icons.json b/homeassistant/components/reolink/icons.json index a9c231bf68f..26198a11594 100644 --- a/homeassistant/components/reolink/icons.json +++ b/homeassistant/components/reolink/icons.json @@ -371,6 +371,12 @@ }, "led": { "default": "mdi:lightning-bolt-circle" + }, + "privacy_mode": { + "default": "mdi:eye", + "state": { + "on": "mdi:eye-off" + } } } }, diff --git a/homeassistant/components/reolink/strings.json b/homeassistant/components/reolink/strings.json index 412362fc447..1cadc16f818 100644 --- a/homeassistant/components/reolink/strings.json +++ b/homeassistant/components/reolink/strings.json @@ -808,6 +808,9 @@ }, "led": { "name": "LED" + }, + "privacy_mode": { + "name": "Privacy mode" } } } diff --git a/homeassistant/components/reolink/switch.py b/homeassistant/components/reolink/switch.py index 85c35b5c987..cecb0b0000f 100644 --- a/homeassistant/components/reolink/switch.py +++ b/homeassistant/components/reolink/switch.py @@ -208,6 +208,17 @@ SWITCH_ENTITIES = ( ), ) +AVAILABILITY_SWITCH_ENTITIES = ( + ReolinkSwitchEntityDescription( + key="privacy_mode", + translation_key="privacy_mode", + entity_category=EntityCategory.CONFIG, + supported=lambda api, ch: api.supported(ch, "privacy_mode"), + value=lambda api, ch: api.baichuan.privacy_mode(ch), + method=lambda api, ch, value: api.baichuan.set_privacy_mode(ch, value), + ), +) + NVR_SWITCH_ENTITIES = ( ReolinkNVRSwitchEntityDescription( key="email", @@ -344,6 +355,12 @@ async def async_setup_entry( for entity_description in CHIME_SWITCH_ENTITIES for chime in reolink_data.host.api.chime_list ) + entities.extend( + ReolinkAvailabilitySwitchEntity(reolink_data, channel, entity_description) + for entity_description in AVAILABILITY_SWITCH_ENTITIES + for channel in reolink_data.host.api.channels + if entity_description.supported(reolink_data.host.api, channel) + ) # Can be removed in HA 2025.4.0 depricated_dict = {} @@ -409,6 +426,15 @@ class ReolinkSwitchEntity(ReolinkChannelCoordinatorEntity, SwitchEntity): self.async_write_ha_state() +class ReolinkAvailabilitySwitchEntity(ReolinkSwitchEntity): + """Switch entity class for Reolink IP cameras which will be available even if API is unavailable.""" + + @property + def available(self) -> bool: + """Return True if entity is available.""" + return self._host.api.camera_online(self._channel) + + class ReolinkNVRSwitchEntity(ReolinkHostCoordinatorEntity, SwitchEntity): """Switch entity class for Reolink NVR features."""