Use shorthand attributes in xs1 climate (#145298)

* Use shorthand attributes in xs1 climate

* Improve
This commit is contained in:
epenet 2025-05-20 10:42:41 +02:00 committed by GitHub
parent 2e4226d7d3
commit 15915680b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,6 +5,8 @@ from __future__ import annotations
from typing import Any
from xs1_api_client.api_constants import ActuatorType
from xs1_api_client.device.actuator import XS1Actuator
from xs1_api_client.device.sensor import XS1Sensor
from homeassistant.components.climate import (
ClimateEntity,
@ -19,9 +21,6 @@ from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from . import ACTUATORS, DOMAIN, SENSORS
from .entity import XS1DeviceEntity
MIN_TEMP = 8
MAX_TEMP = 25
def setup_platform(
hass: HomeAssistant,
@ -30,8 +29,8 @@ def setup_platform(
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up the XS1 thermostat platform."""
actuators = hass.data[DOMAIN][ACTUATORS]
sensors = hass.data[DOMAIN][SENSORS]
actuators: list[XS1Actuator] = hass.data[DOMAIN][ACTUATORS]
sensors: list[XS1Sensor] = hass.data[DOMAIN][SENSORS]
thermostat_entities = []
for actuator in actuators:
@ -56,19 +55,21 @@ class XS1ThermostatEntity(XS1DeviceEntity, ClimateEntity):
_attr_hvac_mode = HVACMode.HEAT
_attr_hvac_modes = [HVACMode.HEAT]
_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
_attr_min_temp = 8
_attr_max_temp = 25
def __init__(self, device, sensor):
def __init__(self, device: XS1Actuator, sensor: XS1Sensor) -> None:
"""Initialize the actuator."""
super().__init__(device)
self.sensor = sensor
@property
def name(self):
def name(self) -> str:
"""Return the name of the device if any."""
return self.device.name()
@property
def current_temperature(self):
def current_temperature(self) -> float | None:
"""Return the current temperature."""
if self.sensor is None:
return None
@ -81,20 +82,10 @@ class XS1ThermostatEntity(XS1DeviceEntity, ClimateEntity):
return self.device.unit()
@property
def target_temperature(self):
def target_temperature(self) -> float | None:
"""Return the current target temperature."""
return self.device.new_value()
@property
def min_temp(self):
"""Return the minimum temperature."""
return MIN_TEMP
@property
def max_temp(self):
"""Return the maximum temperature."""
return MAX_TEMP
def set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperature."""
temp = kwargs.get(ATTR_TEMPERATURE)