mirror of
https://github.com/home-assistant/core.git
synced 2025-08-05 13:45:12 +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,
|
BinarySensorEntityDescription,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.const import EntityCategory
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
@@ -40,7 +41,7 @@ class ReolinkBinarySensorEntityDescription(
|
|||||||
value: Callable[[Host, int], bool]
|
value: Callable[[Host, int], bool]
|
||||||
|
|
||||||
|
|
||||||
BINARY_SENSORS = (
|
BINARY_PUSH_SENSORS = (
|
||||||
ReolinkBinarySensorEntityDescription(
|
ReolinkBinarySensorEntityDescription(
|
||||||
key="motion",
|
key="motion",
|
||||||
device_class=BinarySensorDeviceClass.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(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
@@ -104,6 +116,13 @@ async def async_setup_entry(
|
|||||||
|
|
||||||
entities: list[ReolinkBinarySensorEntity] = []
|
entities: list[ReolinkBinarySensorEntity] = []
|
||||||
for channel in reolink_data.host.api.channels:
|
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(
|
entities.extend(
|
||||||
[
|
[
|
||||||
ReolinkBinarySensorEntity(reolink_data, channel, entity_description)
|
ReolinkBinarySensorEntity(reolink_data, channel, entity_description)
|
||||||
@@ -116,7 +135,7 @@ async def async_setup_entry(
|
|||||||
|
|
||||||
|
|
||||||
class ReolinkBinarySensorEntity(ReolinkChannelCoordinatorEntity, BinarySensorEntity):
|
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
|
entity_description: ReolinkBinarySensorEntityDescription
|
||||||
|
|
||||||
@@ -142,6 +161,10 @@ class ReolinkBinarySensorEntity(ReolinkChannelCoordinatorEntity, BinarySensorEnt
|
|||||||
"""State of the sensor."""
|
"""State of the sensor."""
|
||||||
return self.entity_description.value(self._host.api, self._channel)
|
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:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Entity created."""
|
"""Entity created."""
|
||||||
await super().async_added_to_hass()
|
await super().async_added_to_hass()
|
||||||
|
@@ -42,6 +42,12 @@
|
|||||||
"state": {
|
"state": {
|
||||||
"on": "mdi:motion-sensor"
|
"on": "mdi:motion-sensor"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"sleep": {
|
||||||
|
"default": "mdi:sleep-off",
|
||||||
|
"state": {
|
||||||
|
"on": "mdi:sleep"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"button": {
|
"button": {
|
||||||
|
@@ -233,6 +233,13 @@
|
|||||||
"off": "[%key:component::binary_sensor::entity_component::gas::state::off%]",
|
"off": "[%key:component::binary_sensor::entity_component::gas::state::off%]",
|
||||||
"on": "[%key:component::binary_sensor::entity_component::gas::state::on%]"
|
"on": "[%key:component::binary_sensor::entity_component::gas::state::on%]"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"sleep": {
|
||||||
|
"name": "Sleep status",
|
||||||
|
"state": {
|
||||||
|
"off": "Awake",
|
||||||
|
"on": "Sleeping"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"button": {
|
"button": {
|
||||||
|
Reference in New Issue
Block a user