mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 03:37:07 +00:00
Make Reolink reboot button always available (#136667)
This commit is contained in:
parent
c7041a97be
commit
66f048f49f
@ -138,6 +138,7 @@ BUTTON_ENTITIES = (
|
|||||||
HOST_BUTTON_ENTITIES = (
|
HOST_BUTTON_ENTITIES = (
|
||||||
ReolinkHostButtonEntityDescription(
|
ReolinkHostButtonEntityDescription(
|
||||||
key="reboot",
|
key="reboot",
|
||||||
|
always_available=True,
|
||||||
device_class=ButtonDeviceClass.RESTART,
|
device_class=ButtonDeviceClass.RESTART,
|
||||||
entity_category=EntityCategory.CONFIG,
|
entity_category=EntityCategory.CONFIG,
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
@ -218,7 +219,7 @@ class ReolinkButtonEntity(ReolinkChannelCoordinatorEntity, ButtonEntity):
|
|||||||
|
|
||||||
|
|
||||||
class ReolinkHostButtonEntity(ReolinkHostCoordinatorEntity, ButtonEntity):
|
class ReolinkHostButtonEntity(ReolinkHostCoordinatorEntity, ButtonEntity):
|
||||||
"""Base button entity class for Reolink IP cameras."""
|
"""Base button entity class for Reolink hosts."""
|
||||||
|
|
||||||
entity_description: ReolinkHostButtonEntityDescription
|
entity_description: ReolinkHostButtonEntityDescription
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ class ReolinkEntityDescription(EntityDescription):
|
|||||||
|
|
||||||
cmd_key: str | None = None
|
cmd_key: str | None = None
|
||||||
cmd_id: int | None = None
|
cmd_id: int | None = None
|
||||||
|
always_available: bool = False
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, kw_only=True)
|
@dataclass(frozen=True, kw_only=True)
|
||||||
@ -92,6 +93,9 @@ class ReolinkHostCoordinatorEntity(CoordinatorEntity[DataUpdateCoordinator[None]
|
|||||||
@property
|
@property
|
||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
"""Return True if entity is available."""
|
"""Return True if entity is available."""
|
||||||
|
if self.entity_description.always_available:
|
||||||
|
return True
|
||||||
|
|
||||||
return (
|
return (
|
||||||
self._host.api.session_active
|
self._host.api.session_active
|
||||||
and not self._host.api.baichuan.privacy_mode()
|
and not self._host.api.baichuan.privacy_mode()
|
||||||
|
@ -206,11 +206,9 @@ SWITCH_ENTITIES = (
|
|||||||
value=lambda api, ch: api.pir_reduce_alarm(ch) is True,
|
value=lambda api, ch: api.pir_reduce_alarm(ch) is True,
|
||||||
method=lambda api, ch, value: api.set_pir(ch, reduce_alarm=value),
|
method=lambda api, ch, value: api.set_pir(ch, reduce_alarm=value),
|
||||||
),
|
),
|
||||||
)
|
|
||||||
|
|
||||||
AVAILABILITY_SWITCH_ENTITIES = (
|
|
||||||
ReolinkSwitchEntityDescription(
|
ReolinkSwitchEntityDescription(
|
||||||
key="privacy_mode",
|
key="privacy_mode",
|
||||||
|
always_available=True,
|
||||||
translation_key="privacy_mode",
|
translation_key="privacy_mode",
|
||||||
entity_category=EntityCategory.CONFIG,
|
entity_category=EntityCategory.CONFIG,
|
||||||
supported=lambda api, ch: api.supported(ch, "privacy_mode"),
|
supported=lambda api, ch: api.supported(ch, "privacy_mode"),
|
||||||
@ -355,12 +353,6 @@ async def async_setup_entry(
|
|||||||
for entity_description in CHIME_SWITCH_ENTITIES
|
for entity_description in CHIME_SWITCH_ENTITIES
|
||||||
for chime in reolink_data.host.api.chime_list
|
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
|
# Can be removed in HA 2025.4.0
|
||||||
depricated_dict = {}
|
depricated_dict = {}
|
||||||
@ -426,15 +418,6 @@ class ReolinkSwitchEntity(ReolinkChannelCoordinatorEntity, SwitchEntity):
|
|||||||
self.async_write_ha_state()
|
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):
|
class ReolinkNVRSwitchEntity(ReolinkHostCoordinatorEntity, SwitchEntity):
|
||||||
"""Switch entity class for Reolink NVR features."""
|
"""Switch entity class for Reolink NVR features."""
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user