1
0
mirror of https://github.com/home-assistant/core.git synced 2026-08-06 13:26:29 +01:00
Files
core/homeassistant/components/melcloud/entity.py
T
Ivan Milchev 876bfd45df Centralize MELCloud entity setup in base entities (#177395)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-27 16:42:14 +02:00

52 lines
1.5 KiB
Python

"""Base entity for MELCloud integration."""
from typing import override
from pymelcloud.atw_device import Zone
from homeassistant.helpers.entity import EntityDescription
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .coordinator import MelCloudDeviceUpdateCoordinator
class MelCloudEntity(CoordinatorEntity[MelCloudDeviceUpdateCoordinator]):
"""Base class for MELCloud entities."""
_attr_has_entity_name = True
@property
@override
def available(self) -> bool:
"""Return True if entity is available."""
return super().available and self.coordinator.device_available
class MelCloudDescriptionEntity(MelCloudEntity):
"""Base class for description-driven MELCloud device entities."""
def __init__(
self,
coordinator: MelCloudDeviceUpdateCoordinator,
description: EntityDescription,
) -> None:
"""Initialize the entity."""
super().__init__(coordinator)
self.entity_description = description
self._attr_unique_id = (
f"{coordinator.device.serial}-{coordinator.device.mac}-{description.key}"
)
self._attr_device_info = coordinator.device_info
class AtwZoneEntity(MelCloudEntity):
"""Base class for Air-to-Water zone entities."""
def __init__(
self, coordinator: MelCloudDeviceUpdateCoordinator, zone: Zone
) -> None:
"""Initialize the zone entity."""
super().__init__(coordinator)
self._zone = zone
self._attr_device_info = coordinator.zone_device_info(zone)