mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Add base entity class for Touchline zones (#131094)
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
parent
a252faf9af
commit
7d5ba342c6
@ -2,8 +2,6 @@
|
||||
|
||||
from typing import Any
|
||||
|
||||
from pytouchlinesl import Zone
|
||||
|
||||
from homeassistant.components.climate import (
|
||||
ClimateEntity,
|
||||
ClimateEntityFeature,
|
||||
@ -12,13 +10,11 @@ from homeassistant.components.climate import (
|
||||
)
|
||||
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from . import TouchlineSLConfigEntry
|
||||
from .const import DOMAIN
|
||||
from .coordinator import TouchlineSLModuleCoordinator
|
||||
from .entity import TouchlineSLZoneEntity
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
@ -38,10 +34,9 @@ async def async_setup_entry(
|
||||
CONSTANT_TEMPERATURE = "constant_temperature"
|
||||
|
||||
|
||||
class TouchlineSLZone(CoordinatorEntity[TouchlineSLModuleCoordinator], ClimateEntity):
|
||||
class TouchlineSLZone(TouchlineSLZoneEntity, ClimateEntity):
|
||||
"""Roth Touchline SL Zone."""
|
||||
|
||||
_attr_has_entity_name = True
|
||||
_attr_hvac_action = HVACAction.IDLE
|
||||
_attr_hvac_mode = HVACMode.HEAT
|
||||
_attr_hvac_modes = [HVACMode.HEAT]
|
||||
@ -54,22 +49,12 @@ class TouchlineSLZone(CoordinatorEntity[TouchlineSLModuleCoordinator], ClimateEn
|
||||
|
||||
def __init__(self, coordinator: TouchlineSLModuleCoordinator, zone_id: int) -> None:
|
||||
"""Construct a Touchline SL climate zone."""
|
||||
super().__init__(coordinator)
|
||||
self.zone_id: int = zone_id
|
||||
super().__init__(coordinator, zone_id)
|
||||
|
||||
self._attr_unique_id = (
|
||||
f"module-{self.coordinator.data.module.id}-zone-{self.zone_id}"
|
||||
)
|
||||
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, str(zone_id))},
|
||||
name=self.zone.name,
|
||||
manufacturer="Roth",
|
||||
via_device=(DOMAIN, coordinator.data.module.id),
|
||||
model="zone",
|
||||
suggested_area=self.zone.name,
|
||||
)
|
||||
|
||||
# Call this in __init__ so data is populated right away, since it's
|
||||
# already available in the coordinator data.
|
||||
self.set_attr()
|
||||
@ -80,16 +65,6 @@ class TouchlineSLZone(CoordinatorEntity[TouchlineSLModuleCoordinator], ClimateEn
|
||||
self.set_attr()
|
||||
super()._handle_coordinator_update()
|
||||
|
||||
@property
|
||||
def zone(self) -> Zone:
|
||||
"""Return the device object from the coordinator data."""
|
||||
return self.coordinator.data.zones[self.zone_id]
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
"""Return if the device is available."""
|
||||
return super().available and self.zone_id in self.coordinator.data.zones
|
||||
|
||||
async def async_set_temperature(self, **kwargs: Any) -> None:
|
||||
"""Set new target temperature."""
|
||||
if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None:
|
||||
|
38
homeassistant/components/touchline_sl/entity.py
Normal file
38
homeassistant/components/touchline_sl/entity.py
Normal file
@ -0,0 +1,38 @@
|
||||
"""Base class for Touchline SL zone entities."""
|
||||
|
||||
from pytouchlinesl import Zone
|
||||
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import TouchlineSLModuleCoordinator
|
||||
|
||||
|
||||
class TouchlineSLZoneEntity(CoordinatorEntity[TouchlineSLModuleCoordinator]):
|
||||
"""Defines a base Touchline SL zone entity."""
|
||||
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(self, coordinator: TouchlineSLModuleCoordinator, zone_id: int) -> None:
|
||||
"""Initialize touchline entity."""
|
||||
super().__init__(coordinator)
|
||||
self.zone_id = zone_id
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, str(zone_id))},
|
||||
name=self.zone.name,
|
||||
manufacturer="Roth",
|
||||
via_device=(DOMAIN, coordinator.data.module.id),
|
||||
model="zone",
|
||||
suggested_area=self.zone.name,
|
||||
)
|
||||
|
||||
@property
|
||||
def zone(self) -> Zone:
|
||||
"""Return the device object from the coordinator data."""
|
||||
return self.coordinator.data.zones[self.zone_id]
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
"""Return if the device is available."""
|
||||
return super().available and self.zone_id in self.coordinator.data.zones
|
Loading…
x
Reference in New Issue
Block a user