"""Entités Home Assistant partageant le client Arkteos.""" from __future__ import annotations from homeassistant.helpers.entity import Entity from .client import ArkteosClient class ArkteosEntity(Entity): """Base d'entité sans lecture réseau dans ses propriétés.""" _attr_has_entity_name = True def __init__(self, client: ArkteosClient) -> None: self._client = client @property def available(self) -> bool: """Reflète la disponibilité déterminée par le client partagé.""" return self._client.available async def async_added_to_hass(self) -> None: """Abonne l'entité aux changements de disponibilité.""" await super().async_added_to_hass() self._client.add_availability_callback(self._handle_availability) async def async_will_remove_from_hass(self) -> None: """Retire le callback avant la destruction de l'entité.""" self._client.remove_availability_callback(self._handle_availability) await super().async_will_remove_from_hass() def _handle_availability(self, _available: bool) -> None: self.async_write_ha_state()