mirror of
https://github.com/home-assistant/core.git
synced 2025-08-05 05:35:11 +02:00
Add binary "sleeping" sensor to Reolink (#118774)
This commit is contained in:
@@ -21,6 +21,7 @@ from homeassistant.components.binary_sensor import (
|
||||
BinarySensorEntityDescription,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import EntityCategory
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
@@ -40,7 +41,7 @@ class ReolinkBinarySensorEntityDescription(
|
||||
value: Callable[[Host, int], bool]
|
||||
|
||||
|
||||
BINARY_SENSORS = (
|
||||
BINARY_PUSH_SENSORS = (
|
||||
ReolinkBinarySensorEntityDescription(
|
||||
key="motion",
|
||||
device_class=BinarySensorDeviceClass.MOTION,
|
||||
@@ -93,6 +94,17 @@ BINARY_SENSORS = (
|
||||
),
|
||||
)
|
||||
|
||||
BINARY_SENSORS = (
|
||||
ReolinkBinarySensorEntityDescription(
|
||||
key="sleep",
|
||||
cmd_key="GetChannelstatus",
|
||||
translation_key="sleep",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
value=lambda api, ch: api.sleeping(ch),
|
||||
supported=lambda api, ch: api.supported(ch, "sleep"),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
@@ -104,6 +116,13 @@ async def async_setup_entry(
|
||||
|
||||
entities: list[ReolinkBinarySensorEntity] = []
|
||||
for channel in reolink_data.host.api.channels:
|
||||
entities.extend(
|
||||
[
|
||||
ReolinkPushBinarySensorEntity(reolink_data, channel, entity_description)
|
||||
for entity_description in BINARY_PUSH_SENSORS
|
||||
if entity_description.supported(reolink_data.host.api, channel)
|
||||
]
|
||||
)
|
||||
entities.extend(
|
||||
[
|
||||
ReolinkBinarySensorEntity(reolink_data, channel, entity_description)
|
||||
@@ -116,7 +135,7 @@ async def async_setup_entry(
|
||||
|
||||
|
||||
class ReolinkBinarySensorEntity(ReolinkChannelCoordinatorEntity, BinarySensorEntity):
|
||||
"""Base binary-sensor class for Reolink IP camera motion sensors."""
|
||||
"""Base binary-sensor class for Reolink IP camera."""
|
||||
|
||||
entity_description: ReolinkBinarySensorEntityDescription
|
||||
|
||||
@@ -142,6 +161,10 @@ class ReolinkBinarySensorEntity(ReolinkChannelCoordinatorEntity, BinarySensorEnt
|
||||
"""State of the sensor."""
|
||||
return self.entity_description.value(self._host.api, self._channel)
|
||||
|
||||
|
||||
class ReolinkPushBinarySensorEntity(ReolinkBinarySensorEntity):
|
||||
"""Binary-sensor class for Reolink IP camera motion sensors."""
|
||||
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Entity created."""
|
||||
await super().async_added_to_hass()
|
||||
|
@@ -42,6 +42,12 @@
|
||||
"state": {
|
||||
"on": "mdi:motion-sensor"
|
||||
}
|
||||
},
|
||||
"sleep": {
|
||||
"default": "mdi:sleep-off",
|
||||
"state": {
|
||||
"on": "mdi:sleep"
|
||||
}
|
||||
}
|
||||
},
|
||||
"button": {
|
||||
|
@@ -233,6 +233,13 @@
|
||||
"off": "[%key:component::binary_sensor::entity_component::gas::state::off%]",
|
||||
"on": "[%key:component::binary_sensor::entity_component::gas::state::on%]"
|
||||
}
|
||||
},
|
||||
"sleep": {
|
||||
"name": "Sleep status",
|
||||
"state": {
|
||||
"off": "Awake",
|
||||
"on": "Sleeping"
|
||||
}
|
||||
}
|
||||
},
|
||||
"button": {
|
||||
|
Reference in New Issue
Block a user