Home Assistant Unofficial Reference 2024.12.1
entity.py
Go to the documentation of this file.
1 """Bases for Tedee entities."""
2 
3 from aiotedee.lock import TedeeLock
4 
5 from homeassistant.core import callback
6 from homeassistant.helpers.device_registry import DeviceInfo
7 from homeassistant.helpers.entity import EntityDescription
8 from homeassistant.helpers.update_coordinator import CoordinatorEntity
9 
10 from .const import DOMAIN
11 from .coordinator import TedeeApiCoordinator
12 
13 
14 class TedeeEntity(CoordinatorEntity[TedeeApiCoordinator]):
15  """Base class for Tedee entities."""
16 
17  _attr_has_entity_name = True
18 
19  def __init__(
20  self,
21  lock: TedeeLock,
22  coordinator: TedeeApiCoordinator,
23  key: str,
24  ) -> None:
25  """Initialize Tedee entity."""
26  super().__init__(coordinator)
27  self._lock_lock = lock
28  self._attr_unique_id_attr_unique_id = f"{lock.lock_id}-{key}"
29 
30  self._attr_device_info_attr_device_info = DeviceInfo(
31  identifiers={(DOMAIN, str(lock.lock_id))},
32  name=lock.lock_name,
33  manufacturer="Tedee",
34  model=lock.lock_type,
35  model_id=lock.lock_type,
36  via_device=(DOMAIN, coordinator.bridge.serial),
37  )
38 
39  @callback
40  def _handle_coordinator_update(self) -> None:
41  """Handle updated data from the coordinator."""
42  self._lock_lock = self.coordinator.data.get(self._lock_lock.lock_id, self._lock_lock)
44 
45 
47  """Base class for Tedee device entities."""
48 
49  entity_description: EntityDescription
50 
51  def __init__(
52  self,
53  lock: TedeeLock,
54  coordinator: TedeeApiCoordinator,
55  entity_description: EntityDescription,
56  ) -> None:
57  """Initialize Tedee device entity."""
58  super().__init__(lock, coordinator, entity_description.key)
59  self.entity_descriptionentity_description = entity_description
None __init__(self, TedeeLock lock, TedeeApiCoordinator coordinator, EntityDescription entity_description)
Definition: entity.py:56
None __init__(self, TedeeLock lock, TedeeApiCoordinator coordinator, str key)
Definition: entity.py:24