1
0
mirror of https://github.com/home-assistant/core.git synced 2026-06-30 03:06:10 +01:00
Files
core/homeassistant/components/tedee/entity.py
T
Josef Zweck 67059e64e0 Fix tedee entity availability (#172667)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2026-06-01 08:05:26 +02:00

65 lines
1.9 KiB
Python

"""Bases for Tedee entities."""
from aiotedee.models 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.id}-{key}"
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, str(lock.id))},
name=lock.name,
manufacturer="Tedee",
model=lock.type_name,
model_id=lock.type_name,
via_device=(DOMAIN, coordinator.bridge.serial),
)
@property
def available(self) -> bool:
"""Return True if entity is available."""
return super().available and self._lock.is_connected
@callback
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""
self._lock = self.coordinator.data.get(self._lock.id, self._lock)
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