1 """Support for Yale binary sensors."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
7 from datetime
import datetime, timedelta
8 from functools
import partial
11 from yalexs.activity
import Activity, ActivityType
12 from yalexs.doorbell
import DoorbellDetail
13 from yalexs.lock
import LockDetail, LockDoorStatus
14 from yalexs.manager.const
import ACTIVITY_UPDATE_INTERVAL
15 from yalexs.util
import update_lock_detail_from_activity
18 BinarySensorDeviceClass,
20 BinarySensorEntityDescription,
27 from .
import YaleConfigEntry, YaleData
28 from .entity
import YaleDescriptionEntity
30 retrieve_ding_activity,
31 retrieve_doorbell_motion_activity,
32 retrieve_online_state,
33 retrieve_time_based_activity,
36 _LOGGER = logging.getLogger(__name__)
39 seconds=ACTIVITY_UPDATE_INTERVAL.total_seconds() * 3
43 @dataclass(frozen=True, kw_only=True)
45 """Describes Yale binary_sensor entity."""
47 value_fn: Callable[[YaleData, DoorbellDetail | LockDetail], Activity |
None]
53 device_class=BinarySensorDeviceClass.DOOR,
56 SENSOR_TYPES_VIDEO_DOORBELL = (
59 device_class=BinarySensorDeviceClass.MOTION,
60 value_fn=retrieve_doorbell_motion_activity,
65 translation_key=
"image_capture",
67 retrieve_time_based_activity, {ActivityType.DOORBELL_IMAGE_CAPTURE}
73 device_class=BinarySensorDeviceClass.CONNECTIVITY,
74 entity_category=EntityCategory.DIAGNOSTIC,
75 value_fn=retrieve_online_state,
81 SENSOR_TYPES_DOORBELL: tuple[YaleDoorbellBinarySensorEntityDescription, ...] = (
84 translation_key=
"ding",
85 device_class=BinarySensorDeviceClass.OCCUPANCY,
86 value_fn=retrieve_ding_activity,
94 config_entry: YaleConfigEntry,
95 async_add_entities: AddEntitiesCallback,
97 """Set up the Yale binary sensors."""
98 data = config_entry.runtime_data
99 entities: list[BinarySensorEntity] = []
101 for lock
in data.locks:
102 detail = data.get_device_detail(lock.device_id)
109 for description
in SENSOR_TYPES_DOORBELL
114 for description
in SENSOR_TYPES_DOORBELL + SENSOR_TYPES_VIDEO_DOORBELL
115 for doorbell
in data.doorbells
121 """Representation of an Yale Door binary sensor."""
123 _attr_device_class = BinarySensorDeviceClass.DOOR
124 description: BinarySensorEntityDescription
128 """Get the latest state of the sensor and update activity."""
129 if door_activity := self.
_get_latest_get_latest({ActivityType.DOOR_OPERATION}):
130 update_lock_detail_from_activity(self.
_detail_detail, door_activity)
131 if door_activity.was_pushed:
132 self.
_detail_detail.set_online(
True)
134 if bridge_activity := self.
_get_latest_get_latest({ActivityType.BRIDGE_OPERATION}):
135 update_lock_detail_from_activity(self.
_detail_detail, bridge_activity)
141 """Representation of an Yale binary sensor."""
143 entity_description: YaleDoorbellBinarySensorEntityDescription
144 _check_for_off_update_listener: Callable[[],
None] |
None =
None
148 """Get the latest state of the sensor."""
162 """Timer callback for sensor update."""
169 """Schedule an update to recheck the sensor to see if it is ready to turn off."""
178 """Cancel any updates to recheck a sensor to see if it is ready to turn off."""
181 _LOGGER.debug(
"%s: canceled pending update", self.
entity_identity_id)
186 """When removing cancel any scheduled updates."""
None _update_from_data(self)
None _async_scheduled_update(self, datetime now)
_check_for_off_update_listener
None _schedule_update_to_recheck_turn_off_sensor(self)
None async_will_remove_from_hass(self)
None _cancel_any_pending_updates(self)
None _update_from_data(self)
None _update_from_data(self)
DoorbellDetail|LockDetail _detail(self)
Activity|None _get_latest(self, set[ActivityType] activity_types)
None async_write_ha_state(self)
bool retrieve_online_state(AugustData data, DoorbellDetail|LockDetail detail)
None async_setup_entry(HomeAssistant hass, YaleConfigEntry config_entry, AddEntitiesCallback async_add_entities)
CALLBACK_TYPE async_call_later(HomeAssistant hass, float|timedelta delay, HassJob[[datetime], Coroutine[Any, Any, None]|None]|Callable[[datetime], Coroutine[Any, Any, None]|None] action)