Add Reolink privacy switch entity (#136521)

This commit is contained in:
starkillerOG 2025-01-26 20:03:13 +01:00 committed by GitHub
parent db2fed2034
commit 40127a5ca4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 35 additions and 0 deletions

View File

@ -371,6 +371,12 @@
},
"led": {
"default": "mdi:lightning-bolt-circle"
},
"privacy_mode": {
"default": "mdi:eye",
"state": {
"on": "mdi:eye-off"
}
}
}
},

View File

@ -808,6 +808,9 @@
},
"led": {
"name": "LED"
},
"privacy_mode": {
"name": "Privacy mode"
}
}
}

View File

@ -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."""