Add type hints to LCN (#52509)
* Add type hints to LCN * Fix requested review changes
This commit is contained in:
parent
b496469a2f
commit
e16ef10af5
13 changed files with 333 additions and 172 deletions
|
@ -1,4 +1,8 @@
|
|||
"""Support for LCN climate control."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, cast
|
||||
|
||||
import pypck
|
||||
|
||||
from homeassistant.components.climate import (
|
||||
|
@ -6,6 +10,7 @@ from homeassistant.components.climate import (
|
|||
ClimateEntity,
|
||||
const,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_TEMPERATURE,
|
||||
CONF_ADDRESS,
|
||||
|
@ -14,6 +19,8 @@ from homeassistant.const import (
|
|||
CONF_SOURCE,
|
||||
CONF_UNIT_OF_MEASUREMENT,
|
||||
)
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, HomeAssistantType
|
||||
|
||||
from . import LcnEntity
|
||||
from .const import (
|
||||
|
@ -23,21 +30,27 @@ from .const import (
|
|||
CONF_MIN_TEMP,
|
||||
CONF_SETPOINT,
|
||||
)
|
||||
from .helpers import get_device_connection
|
||||
from .helpers import DeviceConnectionType, InputType, get_device_connection
|
||||
|
||||
PARALLEL_UPDATES = 0
|
||||
|
||||
|
||||
def create_lcn_climate_entity(hass, entity_config, config_entry):
|
||||
def create_lcn_climate_entity(
|
||||
hass: HomeAssistantType, entity_config: ConfigType, config_entry: ConfigEntry
|
||||
) -> LcnEntity:
|
||||
"""Set up an entity for this domain."""
|
||||
device_connection = get_device_connection(
|
||||
hass, tuple(entity_config[CONF_ADDRESS]), config_entry
|
||||
hass, entity_config[CONF_ADDRESS], config_entry
|
||||
)
|
||||
|
||||
return LcnClimate(entity_config, config_entry.entry_id, device_connection)
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistantType,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up LCN switch entities from a config entry."""
|
||||
entities = []
|
||||
|
||||
|
@ -53,7 +66,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
class LcnClimate(LcnEntity, ClimateEntity):
|
||||
"""Representation of a LCN climate device."""
|
||||
|
||||
def __init__(self, config, entry_id, device_connection):
|
||||
def __init__(
|
||||
self, config: ConfigType, entry_id: str, device_connection: DeviceConnectionType
|
||||
) -> None:
|
||||
"""Initialize of a LCN climate device."""
|
||||
super().__init__(config, entry_id, device_connection)
|
||||
|
||||
|
@ -72,14 +87,14 @@ class LcnClimate(LcnEntity, ClimateEntity):
|
|||
self._target_temperature = None
|
||||
self._is_on = True
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Run when entity about to be added to hass."""
|
||||
await super().async_added_to_hass()
|
||||
if not self.device_connection.is_group:
|
||||
await self.device_connection.activate_status_request_handler(self.variable)
|
||||
await self.device_connection.activate_status_request_handler(self.setpoint)
|
||||
|
||||
async def async_will_remove_from_hass(self):
|
||||
async def async_will_remove_from_hass(self) -> None:
|
||||
"""Run when entity will be removed from hass."""
|
||||
await super().async_will_remove_from_hass()
|
||||
if not self.device_connection.is_group:
|
||||
|
@ -87,27 +102,27 @@ class LcnClimate(LcnEntity, ClimateEntity):
|
|||
await self.device_connection.cancel_status_request_handler(self.setpoint)
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
def supported_features(self) -> int:
|
||||
"""Return the list of supported features."""
|
||||
return const.SUPPORT_TARGET_TEMPERATURE
|
||||
|
||||
@property
|
||||
def temperature_unit(self):
|
||||
def temperature_unit(self) -> str:
|
||||
"""Return the unit of measurement."""
|
||||
return self.unit.value
|
||||
return cast(str, self.unit.value)
|
||||
|
||||
@property
|
||||
def current_temperature(self):
|
||||
def current_temperature(self) -> float | None:
|
||||
"""Return the current temperature."""
|
||||
return self._current_temperature
|
||||
|
||||
@property
|
||||
def target_temperature(self):
|
||||
def target_temperature(self) -> float | None:
|
||||
"""Return the temperature we try to reach."""
|
||||
return self._target_temperature
|
||||
|
||||
@property
|
||||
def hvac_mode(self):
|
||||
def hvac_mode(self) -> str:
|
||||
"""Return hvac operation ie. heat, cool mode.
|
||||
|
||||
Need to be one of HVAC_MODE_*.
|
||||
|
@ -117,7 +132,7 @@ class LcnClimate(LcnEntity, ClimateEntity):
|
|||
return const.HVAC_MODE_OFF
|
||||
|
||||
@property
|
||||
def hvac_modes(self):
|
||||
def hvac_modes(self) -> list[str]:
|
||||
"""Return the list of available hvac operation modes.
|
||||
|
||||
Need to be a subset of HVAC_MODES.
|
||||
|
@ -128,16 +143,16 @@ class LcnClimate(LcnEntity, ClimateEntity):
|
|||
return modes
|
||||
|
||||
@property
|
||||
def max_temp(self):
|
||||
def max_temp(self) -> float:
|
||||
"""Return the maximum temperature."""
|
||||
return self._max_temp
|
||||
return cast(float, self._max_temp)
|
||||
|
||||
@property
|
||||
def min_temp(self):
|
||||
def min_temp(self) -> float:
|
||||
"""Return the minimum temperature."""
|
||||
return self._min_temp
|
||||
return cast(float, self._min_temp)
|
||||
|
||||
async def async_set_hvac_mode(self, hvac_mode):
|
||||
async def async_set_hvac_mode(self, hvac_mode: str) -> None:
|
||||
"""Set new target hvac mode."""
|
||||
if hvac_mode == const.HVAC_MODE_HEAT:
|
||||
if not await self.device_connection.lock_regulator(
|
||||
|
@ -153,7 +168,7 @@ class LcnClimate(LcnEntity, ClimateEntity):
|
|||
self._target_temperature = None
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_set_temperature(self, **kwargs):
|
||||
async def async_set_temperature(self, **kwargs: Any) -> None:
|
||||
"""Set new target temperature."""
|
||||
temperature = kwargs.get(ATTR_TEMPERATURE)
|
||||
if temperature is None:
|
||||
|
@ -166,7 +181,7 @@ class LcnClimate(LcnEntity, ClimateEntity):
|
|||
self._target_temperature = temperature
|
||||
self.async_write_ha_state()
|
||||
|
||||
def input_received(self, input_obj):
|
||||
def input_received(self, input_obj: InputType) -> None:
|
||||
"""Set temperature value when LCN input object is received."""
|
||||
if not isinstance(input_obj, pypck.inputs.ModStatusVar):
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue