1
mirror of https://github.com/home-assistant/core synced 2024-08-28 03:36:46 +02:00
ha-core/homeassistant/components/tedee/entity.py
Josef Zweck 87c79ef57f
Add tedee bridge as via_device for tedee integration (#106914)
* add bridge as via_device

* add bridge as via_device

* move getting bridge to update_data

* add bridge property
2024-01-02 23:23:50 +01:00

59 lines
1.7 KiB
Python

"""Bases for Tedee entities."""
from pytedee_async.lock import TedeeLock
from homeassistant.core import callback
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity import EntityDescription
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import DOMAIN
from .coordinator import TedeeApiCoordinator
class TedeeEntity(CoordinatorEntity[TedeeApiCoordinator]):
"""Base class for Tedee entities."""
_attr_has_entity_name = True
def __init__(
self,
lock: TedeeLock,
coordinator: TedeeApiCoordinator,
key: str,
) -> None:
"""Initialize Tedee entity."""
super().__init__(coordinator)
self._lock = lock
self._attr_unique_id = f"{lock.lock_id}-{key}"
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, str(lock.lock_id))},
name=lock.lock_name,
manufacturer="Tedee",
model=lock.lock_type,
via_device=(DOMAIN, coordinator.bridge.serial),
)
@callback
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""
self._lock = self.coordinator.data[self._lock.lock_id]
super()._handle_coordinator_update()
class TedeeDescriptionEntity(TedeeEntity):
"""Base class for Tedee device entities."""
entity_description: EntityDescription
def __init__(
self,
lock: TedeeLock,
coordinator: TedeeApiCoordinator,
entity_description: EntityDescription,
) -> None:
"""Initialize Tedee device entity."""
super().__init__(lock, coordinator, entity_description.key)
self.entity_description = entity_description