Use climate enums in lcn (#70679)

This commit is contained in:
epenet 2022-04-26 09:37:13 +02:00 committed by GitHub
parent f85e225227
commit f2b7390ee7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,11 +5,8 @@ from typing import Any, cast
import pypck import pypck
from homeassistant.components.climate import ( from homeassistant.components.climate import DOMAIN as DOMAIN_CLIMATE, ClimateEntity
DOMAIN as DOMAIN_CLIMATE, from homeassistant.components.climate.const import ClimateEntityFeature, HVACMode
ClimateEntity,
const,
)
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
ATTR_TEMPERATURE, ATTR_TEMPERATURE,
@ -69,6 +66,8 @@ async def async_setup_entry(
class LcnClimate(LcnEntity, ClimateEntity): class LcnClimate(LcnEntity, ClimateEntity):
"""Representation of a LCN climate device.""" """Representation of a LCN climate device."""
_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
def __init__( def __init__(
self, config: ConfigType, entry_id: str, device_connection: DeviceConnectionType self, config: ConfigType, entry_id: str, device_connection: DeviceConnectionType
) -> None: ) -> None:
@ -90,6 +89,10 @@ class LcnClimate(LcnEntity, ClimateEntity):
self._target_temperature = None self._target_temperature = None
self._is_on = True self._is_on = True
self._attr_hvac_modes = [HVACMode.HEAT]
if self.is_lockable:
self._attr_hvac_modes.append(HVACMode.OFF)
async def async_added_to_hass(self) -> None: async def async_added_to_hass(self) -> None:
"""Run when entity about to be added to hass.""" """Run when entity about to be added to hass."""
await super().async_added_to_hass() await super().async_added_to_hass()
@ -104,11 +107,6 @@ class LcnClimate(LcnEntity, ClimateEntity):
await self.device_connection.cancel_status_request_handler(self.variable) await self.device_connection.cancel_status_request_handler(self.variable)
await self.device_connection.cancel_status_request_handler(self.setpoint) await self.device_connection.cancel_status_request_handler(self.setpoint)
@property
def supported_features(self) -> int:
"""Return the list of supported features."""
return const.SUPPORT_TARGET_TEMPERATURE
@property @property
def temperature_unit(self) -> str: def temperature_unit(self) -> str:
"""Return the unit of measurement.""" """Return the unit of measurement."""
@ -128,25 +126,14 @@ class LcnClimate(LcnEntity, ClimateEntity):
return self._target_temperature return self._target_temperature
@property @property
def hvac_mode(self) -> str: def hvac_mode(self) -> HVACMode:
"""Return hvac operation ie. heat, cool mode. """Return hvac operation ie. heat, cool mode.
Need to be one of HVAC_MODE_*. Need to be one of HVAC_MODE_*.
""" """
if self._is_on: if self._is_on:
return const.HVAC_MODE_HEAT return HVACMode.HEAT
return const.HVAC_MODE_OFF return HVACMode.OFF
@property
def hvac_modes(self) -> list[str]:
"""Return the list of available hvac operation modes.
Need to be a subset of HVAC_MODES.
"""
modes = [const.HVAC_MODE_HEAT]
if self.is_lockable:
modes.append(const.HVAC_MODE_OFF)
return modes
@property @property
def max_temp(self) -> float: def max_temp(self) -> float:
@ -158,16 +145,16 @@ class LcnClimate(LcnEntity, ClimateEntity):
"""Return the minimum temperature.""" """Return the minimum temperature."""
return cast(float, self._min_temp) return cast(float, self._min_temp)
async def async_set_hvac_mode(self, hvac_mode: str) -> None: async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
"""Set new target hvac mode.""" """Set new target hvac mode."""
if hvac_mode == const.HVAC_MODE_HEAT: if hvac_mode == HVACMode.HEAT:
if not await self.device_connection.lock_regulator( if not await self.device_connection.lock_regulator(
self.regulator_id, False self.regulator_id, False
): ):
return return
self._is_on = True self._is_on = True
self.async_write_ha_state() self.async_write_ha_state()
elif hvac_mode == const.HVAC_MODE_OFF: elif hvac_mode == HVACMode.OFF:
if not await self.device_connection.lock_regulator(self.regulator_id, True): if not await self.device_connection.lock_regulator(self.regulator_id, True):
return return
self._is_on = False self._is_on = False