mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Refactor incomfort platform attributes (#118667)
* Refector incomfort platform attributes * Initialize static entity properties as class level
This commit is contained in:
parent
7c5a6602b3
commit
bb259b607f
@ -73,25 +73,6 @@ async def async_setup(hass: HomeAssistant, hass_config: ConfigType) -> bool:
|
||||
class IncomfortEntity(Entity):
|
||||
"""Base class for all InComfort entities."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""Initialize the class."""
|
||||
self._name: str | None = None
|
||||
self._unique_id: str | None = None
|
||||
|
||||
@property
|
||||
def unique_id(self) -> str | None:
|
||||
"""Return a unique ID."""
|
||||
return self._unique_id
|
||||
|
||||
@property
|
||||
def name(self) -> str | None:
|
||||
"""Return the name of the sensor."""
|
||||
return self._name
|
||||
|
||||
|
||||
class IncomfortChild(IncomfortEntity):
|
||||
"""Base class for all InComfort entities (excluding the boiler)."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
async def async_added_to_hass(self) -> None:
|
||||
|
@ -4,15 +4,14 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
DOMAIN as BINARY_SENSOR_DOMAIN,
|
||||
BinarySensorEntity,
|
||||
)
|
||||
from incomfortclient import Gateway as InComfortGateway, Heater as InComfortHeater
|
||||
|
||||
from homeassistant.components.binary_sensor import BinarySensorEntity
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from . import DOMAIN, IncomfortChild
|
||||
from . import DOMAIN, IncomfortEntity
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
@ -31,20 +30,20 @@ async def async_setup_platform(
|
||||
async_add_entities([IncomfortFailed(client, h) for h in heaters])
|
||||
|
||||
|
||||
class IncomfortFailed(IncomfortChild, BinarySensorEntity):
|
||||
class IncomfortFailed(IncomfortEntity, BinarySensorEntity):
|
||||
"""Representation of an InComfort Failed sensor."""
|
||||
|
||||
def __init__(self, client, heater) -> None:
|
||||
_attr_name = "Fault"
|
||||
|
||||
def __init__(self, client: InComfortGateway, heater: InComfortHeater) -> None:
|
||||
"""Initialize the binary sensor."""
|
||||
super().__init__()
|
||||
|
||||
self._unique_id = f"{heater.serial_no}_failed"
|
||||
self.entity_id = f"{BINARY_SENSOR_DOMAIN}.{DOMAIN}_failed"
|
||||
self._name = "Boiler Fault"
|
||||
|
||||
self._client = client
|
||||
self._heater = heater
|
||||
|
||||
self._attr_unique_id = f"{heater.serial_no}_failed"
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
"""Return the status of the sensor."""
|
||||
|
@ -4,8 +4,13 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from incomfortclient import (
|
||||
Gateway as InComfortGateway,
|
||||
Heater as InComfortHeater,
|
||||
Room as InComfortRoom,
|
||||
)
|
||||
|
||||
from homeassistant.components.climate import (
|
||||
DOMAIN as CLIMATE_DOMAIN,
|
||||
ClimateEntity,
|
||||
ClimateEntityFeature,
|
||||
HVACMode,
|
||||
@ -15,7 +20,7 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from . import DOMAIN, IncomfortChild
|
||||
from . import DOMAIN, IncomfortEntity
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
@ -36,26 +41,29 @@ async def async_setup_platform(
|
||||
)
|
||||
|
||||
|
||||
class InComfortClimate(IncomfortChild, ClimateEntity):
|
||||
class InComfortClimate(IncomfortEntity, ClimateEntity):
|
||||
"""Representation of an InComfort/InTouch climate device."""
|
||||
|
||||
_attr_min_temp = 5.0
|
||||
_attr_max_temp = 30.0
|
||||
_attr_hvac_mode = HVACMode.HEAT
|
||||
_attr_hvac_modes = [HVACMode.HEAT]
|
||||
_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
|
||||
_attr_temperature_unit = UnitOfTemperature.CELSIUS
|
||||
_enable_turn_on_off_backwards_compatibility = False
|
||||
|
||||
def __init__(self, client, heater, room) -> None:
|
||||
def __init__(
|
||||
self, client: InComfortGateway, heater: InComfortHeater, room: InComfortRoom
|
||||
) -> None:
|
||||
"""Initialize the climate device."""
|
||||
super().__init__()
|
||||
|
||||
self._unique_id = f"{heater.serial_no}_{room.room_no}"
|
||||
self.entity_id = f"{CLIMATE_DOMAIN}.{DOMAIN}_{room.room_no}"
|
||||
self._name = f"Thermostat {room.room_no}"
|
||||
|
||||
self._client = client
|
||||
self._room = room
|
||||
|
||||
self._attr_unique_id = f"{heater.serial_no}_{room.room_no}"
|
||||
self._attr_name = f"Thermostat {room.room_no}"
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self) -> dict[str, Any]:
|
||||
"""Return the device state attributes."""
|
||||
@ -71,16 +79,6 @@ class InComfortClimate(IncomfortChild, ClimateEntity):
|
||||
"""Return the temperature we try to reach."""
|
||||
return self._room.setpoint
|
||||
|
||||
@property
|
||||
def min_temp(self) -> float:
|
||||
"""Return max valid temperature that can be set."""
|
||||
return 5.0
|
||||
|
||||
@property
|
||||
def max_temp(self) -> float:
|
||||
"""Return max valid temperature that can be set."""
|
||||
return 30.0
|
||||
|
||||
async def async_set_temperature(self, **kwargs: Any) -> None:
|
||||
"""Set a new target temperature for this zone."""
|
||||
temperature = kwargs.get(ATTR_TEMPERATURE)
|
||||
|
@ -5,8 +5,9 @@ from __future__ import annotations
|
||||
from dataclasses import dataclass
|
||||
from typing import Any
|
||||
|
||||
from incomfortclient import Gateway as InComfortGateway, Heater as InComfortHeater
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
DOMAIN as SENSOR_DOMAIN,
|
||||
SensorDeviceClass,
|
||||
SensorEntity,
|
||||
SensorEntityDescription,
|
||||
@ -17,7 +18,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.util import slugify
|
||||
|
||||
from . import DOMAIN, IncomfortChild
|
||||
from . import DOMAIN, IncomfortEntity
|
||||
|
||||
INCOMFORT_HEATER_TEMP = "CV Temp"
|
||||
INCOMFORT_PRESSURE = "CV Pressure"
|
||||
@ -80,13 +81,16 @@ async def async_setup_platform(
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class IncomfortSensor(IncomfortChild, SensorEntity):
|
||||
class IncomfortSensor(IncomfortEntity, SensorEntity):
|
||||
"""Representation of an InComfort/InTouch sensor device."""
|
||||
|
||||
entity_description: IncomfortSensorEntityDescription
|
||||
|
||||
def __init__(
|
||||
self, client, heater, description: IncomfortSensorEntityDescription
|
||||
self,
|
||||
client: InComfortGateway,
|
||||
heater: InComfortHeater,
|
||||
description: IncomfortSensorEntityDescription,
|
||||
) -> None:
|
||||
"""Initialize the sensor."""
|
||||
super().__init__()
|
||||
@ -95,9 +99,7 @@ class IncomfortSensor(IncomfortChild, SensorEntity):
|
||||
self._client = client
|
||||
self._heater = heater
|
||||
|
||||
self._unique_id = f"{heater.serial_no}_{slugify(description.name)}"
|
||||
self.entity_id = f"{SENSOR_DOMAIN}.{DOMAIN}_{slugify(description.name)}"
|
||||
self._name = f"Boiler {description.name}"
|
||||
self._attr_unique_id = f"{heater.serial_no}_{slugify(description.name)}"
|
||||
|
||||
@property
|
||||
def native_value(self) -> str | None:
|
||||
|
@ -6,11 +6,9 @@ import logging
|
||||
from typing import Any
|
||||
|
||||
from aiohttp import ClientResponseError
|
||||
from incomfortclient import Gateway as InComfortGateway, Heater as InComfortHeater
|
||||
|
||||
from homeassistant.components.water_heater import (
|
||||
DOMAIN as WATER_HEATER_DOMAIN,
|
||||
WaterHeaterEntity,
|
||||
)
|
||||
from homeassistant.components.water_heater import WaterHeaterEntity
|
||||
from homeassistant.const import UnitOfTemperature
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
@ -43,17 +41,21 @@ async def async_setup_platform(
|
||||
class IncomfortWaterHeater(IncomfortEntity, WaterHeaterEntity):
|
||||
"""Representation of an InComfort/Intouch water_heater device."""
|
||||
|
||||
def __init__(self, client, heater) -> None:
|
||||
_attr_min_temp = 30.0
|
||||
_attr_max_temp = 80.0
|
||||
_attr_name = "Boiler"
|
||||
_attr_should_poll = True
|
||||
_attr_temperature_unit = UnitOfTemperature.CELSIUS
|
||||
|
||||
def __init__(self, client: InComfortGateway, heater: InComfortHeater) -> None:
|
||||
"""Initialize the water_heater device."""
|
||||
super().__init__()
|
||||
|
||||
self._unique_id = f"{heater.serial_no}"
|
||||
self.entity_id = f"{WATER_HEATER_DOMAIN}.{DOMAIN}"
|
||||
self._name = "Boiler"
|
||||
|
||||
self._client = client
|
||||
self._heater = heater
|
||||
|
||||
self._attr_unique_id = heater.serial_no
|
||||
|
||||
@property
|
||||
def icon(self) -> str:
|
||||
"""Return the icon of the water_heater device."""
|
||||
@ -73,21 +75,6 @@ class IncomfortWaterHeater(IncomfortEntity, WaterHeaterEntity):
|
||||
return self._heater.heater_temp
|
||||
return max(self._heater.heater_temp, self._heater.tap_temp)
|
||||
|
||||
@property
|
||||
def min_temp(self) -> float:
|
||||
"""Return min valid temperature that can be set."""
|
||||
return 30.0
|
||||
|
||||
@property
|
||||
def max_temp(self) -> float:
|
||||
"""Return max valid temperature that can be set."""
|
||||
return 80.0
|
||||
|
||||
@property
|
||||
def temperature_unit(self) -> str:
|
||||
"""Return the unit of measurement."""
|
||||
return UnitOfTemperature.CELSIUS
|
||||
|
||||
@property
|
||||
def current_operation(self) -> str:
|
||||
"""Return the current operation mode."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user