1 """Base class for Yale entity."""
3 from abc
import abstractmethod
5 from yalexs.activity
import Activity, ActivityType
6 from yalexs.doorbell
import Doorbell, DoorbellDetail
7 from yalexs.keypad
import KeypadDetail
8 from yalexs.lock
import Lock, LockDetail
9 from yalexs.util
import get_configuration_url
17 from .
import DOMAIN, YaleData
18 from .const
import MANUFACTURER
20 DEVICE_TYPES = [
"keypad",
"lock",
"camera",
"doorbell",
"door",
"bell"]
24 """Base implementation for Yale device."""
26 _attr_should_poll =
False
27 _attr_has_entity_name =
True
30 self, data: YaleData, device: Doorbell | Lock | KeypadDetail, unique_id: str
32 """Initialize an Yale device."""
35 self.
_stream_stream = data.activity_stream
41 identifiers={(DOMAIN, self.
_device_id_device_id)},
42 manufacturer=MANUFACTURER,
44 name=device.device_name,
45 sw_version=detail.firmware_version,
47 configuration_url=get_configuration_url(data.brand),
49 if isinstance(detail, LockDetail)
and (mac := detail.mac_address):
50 self.
_attr_device_info_attr_device_info[ATTR_CONNECTIONS] = {(dr.CONNECTION_BLUETOOTH, mac)}
53 def _detail(self) -> DoorbellDetail | LockDetail:
54 return self.
_data_data.get_device_detail(self.
_device_device.device_id)
58 """Check if the lock has a paired hyper bridge."""
62 def _get_latest(self, activity_types: set[ActivityType]) -> Activity |
None:
63 """Get the latest activity for the device."""
64 return self.
_stream_stream.get_latest_device_activity(self.
_device_id_device_id, activity_types)
73 """Update the entity state from the data object."""
76 """Subscribe to updates."""
78 self._data.async_subscribe_device_id(
79 self._device_id, self._update_from_data_and_write_state
83 self._stream.async_subscribe_device_id(
84 self._device_id, self._update_from_data_and_write_state
87 self._update_from_data()
91 """An Yale entity with a description."""
96 device: Doorbell | Lock | KeypadDetail,
97 description: EntityDescription,
99 """Initialize an Yale entity with a description."""
100 super().
__init__(data, device, description.key)
105 """Strip device types from a string.
107 Yale stores the name as Master Bed Lock
108 or Master Bed Door. We can come up with a
109 reasonable suggestion by removing the supported
110 device types from the string.
112 lower_name = name.lower()
113 for device_type
in device_types:
114 lower_name = lower_name.removesuffix(f
" {device_type}")
115 return name[: len(lower_name)]
None __init__(self, YaleData data, Doorbell|Lock|KeypadDetail device, EntityDescription description)
None __init__(self, YaleData data, Doorbell|Lock|KeypadDetail device, str unique_id)
None _update_from_data(self)
None async_added_to_hass(self)
DoorbellDetail|LockDetail _detail(self)
None _update_from_data_and_write_state(self)
Activity|None _get_latest(self, set[ActivityType] activity_types)
None async_write_ha_state(self)
str _remove_device_types(str name, list[str] device_types)