1 """Component providing support for Reolink binary sensors."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
8 from reolink_aio.api
import (
9 DUAL_LENS_DUAL_MOTION_MODELS,
11 PACKAGE_DETECTION_TYPE,
12 PERSON_DETECTION_TYPE,
14 VEHICLE_DETECTION_TYPE,
19 BinarySensorDeviceClass,
21 BinarySensorEntityDescription,
28 from .entity
import ReolinkChannelCoordinatorEntity, ReolinkChannelEntityDescription
29 from .util
import ReolinkConfigEntry, ReolinkData
34 @dataclass(frozen=True, kw_only=True)
36 BinarySensorEntityDescription,
37 ReolinkChannelEntityDescription,
39 """A class that describes binary sensor entities."""
41 value: Callable[[Host, int], bool]
44 BINARY_PUSH_SENSORS = (
48 device_class=BinarySensorDeviceClass.MOTION,
49 value=
lambda api, ch: api.motion_detected(ch),
52 key=FACE_DETECTION_TYPE,
54 translation_key=
"face",
55 value=
lambda api, ch: api.ai_detected(ch, FACE_DETECTION_TYPE),
56 supported=
lambda api, ch: api.ai_supported(ch, FACE_DETECTION_TYPE),
59 key=PERSON_DETECTION_TYPE,
61 translation_key=
"person",
62 value=
lambda api, ch: api.ai_detected(ch, PERSON_DETECTION_TYPE),
63 supported=
lambda api, ch: api.ai_supported(ch, PERSON_DETECTION_TYPE),
66 key=VEHICLE_DETECTION_TYPE,
68 translation_key=
"vehicle",
69 value=
lambda api, ch: api.ai_detected(ch, VEHICLE_DETECTION_TYPE),
70 supported=
lambda api, ch: api.ai_supported(ch, VEHICLE_DETECTION_TYPE),
73 key=PET_DETECTION_TYPE,
75 translation_key=
"pet",
76 value=
lambda api, ch: api.ai_detected(ch, PET_DETECTION_TYPE),
77 supported=
lambda api, ch: (
78 api.ai_supported(ch, PET_DETECTION_TYPE)
79 and not api.supported(ch,
"ai_animal")
83 key=PET_DETECTION_TYPE,
85 translation_key=
"animal",
86 value=
lambda api, ch: api.ai_detected(ch, PET_DETECTION_TYPE),
87 supported=
lambda api, ch: api.supported(ch,
"ai_animal"),
90 key=PACKAGE_DETECTION_TYPE,
92 translation_key=
"package",
93 value=
lambda api, ch: api.ai_detected(ch, PACKAGE_DETECTION_TYPE),
94 supported=
lambda api, ch: api.ai_supported(ch, PACKAGE_DETECTION_TYPE),
99 translation_key=
"visitor",
100 value=
lambda api, ch: api.visitor_detected(ch),
101 supported=
lambda api, ch: api.is_doorbell(ch),
109 cmd_key=
"GetChannelstatus",
110 translation_key=
"sleep",
111 entity_category=EntityCategory.DIAGNOSTIC,
112 value=
lambda api, ch: api.sleeping(ch),
113 supported=
lambda api, ch: api.supported(ch,
"sleep"),
120 config_entry: ReolinkConfigEntry,
121 async_add_entities: AddEntitiesCallback,
123 """Set up a Reolink IP Camera."""
124 reolink_data: ReolinkData = config_entry.runtime_data
126 entities: list[ReolinkBinarySensorEntity] = []
127 for channel
in reolink_data.host.api.channels:
130 for entity_description
in BINARY_PUSH_SENSORS
131 if entity_description.supported(reolink_data.host.api, channel)
135 for entity_description
in BINARY_SENSORS
136 if entity_description.supported(reolink_data.host.api, channel)
143 """Base binary-sensor class for Reolink IP camera."""
145 entity_description: ReolinkBinarySensorEntityDescription
149 reolink_data: ReolinkData,
151 entity_description: ReolinkBinarySensorEntityDescription,
153 """Initialize Reolink binary sensor."""
155 super().
__init__(reolink_data, channel)
157 if self.
_host_host.api.model
in DUAL_LENS_DUAL_MOTION_MODELS:
158 if entity_description.translation_key
is not None:
159 key = entity_description.translation_key
161 key = entity_description.key
166 """State of the sensor."""
171 """Binary-sensor class for Reolink IP camera motion sensors."""
174 """Entity created."""
179 f
"{self._host.unique_id}_{self._channel}",
186 f
"{self._host.unique_id}_all",
192 """Handle incoming event for motion detection."""
None __init__(self, ReolinkData reolink_data, int channel, ReolinkBinarySensorEntityDescription entity_description)
None async_added_to_hass(self)
None _async_handle_event(self, str event)
None async_write_ha_state(self)
None async_on_remove(self, CALLBACK_TYPE func)
None async_setup_entry(HomeAssistant hass, ReolinkConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)