mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Improve type hints in econet (#136693)
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
This commit is contained in:
parent
d9d6308b78
commit
f1305cd5a3
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from pyeconet.equipment import EquipmentType
|
from pyeconet.equipment import Equipment, EquipmentType
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import (
|
from homeassistant.components.binary_sensor import (
|
||||||
BinarySensorDeviceClass,
|
BinarySensorDeviceClass,
|
||||||
@ -63,7 +63,7 @@ class EcoNetBinarySensor(EcoNetEntity, BinarySensorEntity):
|
|||||||
"""Define a Econet binary sensor."""
|
"""Define a Econet binary sensor."""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, econet_device, description: BinarySensorEntityDescription
|
self, econet_device: Equipment, description: BinarySensorEntityDescription
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
super().__init__(econet_device)
|
super().__init__(econet_device)
|
||||||
|
@ -3,7 +3,11 @@
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from pyeconet.equipment import EquipmentType
|
from pyeconet.equipment import EquipmentType
|
||||||
from pyeconet.equipment.thermostat import ThermostatFanMode, ThermostatOperationMode
|
from pyeconet.equipment.thermostat import (
|
||||||
|
Thermostat,
|
||||||
|
ThermostatFanMode,
|
||||||
|
ThermostatOperationMode,
|
||||||
|
)
|
||||||
|
|
||||||
from homeassistant.components.climate import (
|
from homeassistant.components.climate import (
|
||||||
ATTR_TARGET_TEMP_HIGH,
|
ATTR_TARGET_TEMP_HIGH,
|
||||||
@ -65,13 +69,13 @@ async def async_setup_entry(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class EcoNetThermostat(EcoNetEntity, ClimateEntity):
|
class EcoNetThermostat(EcoNetEntity[Thermostat], ClimateEntity):
|
||||||
"""Define an Econet thermostat."""
|
"""Define an Econet thermostat."""
|
||||||
|
|
||||||
_attr_should_poll = True
|
_attr_should_poll = True
|
||||||
_attr_temperature_unit = UnitOfTemperature.FAHRENHEIT
|
_attr_temperature_unit = UnitOfTemperature.FAHRENHEIT
|
||||||
|
|
||||||
def __init__(self, thermostat):
|
def __init__(self, thermostat: Thermostat) -> None:
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
super().__init__(thermostat)
|
super().__init__(thermostat)
|
||||||
self._attr_hvac_modes = []
|
self._attr_hvac_modes = []
|
||||||
@ -92,24 +96,24 @@ class EcoNetThermostat(EcoNetEntity, ClimateEntity):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_temperature(self):
|
def current_temperature(self) -> int:
|
||||||
"""Return the current temperature."""
|
"""Return the current temperature."""
|
||||||
return self._econet.set_point
|
return self._econet.set_point
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_humidity(self):
|
def current_humidity(self) -> int:
|
||||||
"""Return the current humidity."""
|
"""Return the current humidity."""
|
||||||
return self._econet.humidity
|
return self._econet.humidity
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def target_humidity(self):
|
def target_humidity(self) -> int | None:
|
||||||
"""Return the humidity we try to reach."""
|
"""Return the humidity we try to reach."""
|
||||||
if self._econet.supports_humidifier:
|
if self._econet.supports_humidifier:
|
||||||
return self._econet.dehumidifier_set_point
|
return self._econet.dehumidifier_set_point
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def target_temperature(self):
|
def target_temperature(self) -> int | None:
|
||||||
"""Return the temperature we try to reach."""
|
"""Return the temperature we try to reach."""
|
||||||
if self.hvac_mode == HVACMode.COOL:
|
if self.hvac_mode == HVACMode.COOL:
|
||||||
return self._econet.cool_set_point
|
return self._econet.cool_set_point
|
||||||
@ -118,14 +122,14 @@ class EcoNetThermostat(EcoNetEntity, ClimateEntity):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def target_temperature_low(self):
|
def target_temperature_low(self) -> int | None:
|
||||||
"""Return the lower bound temperature we try to reach."""
|
"""Return the lower bound temperature we try to reach."""
|
||||||
if self.hvac_mode == HVACMode.HEAT_COOL:
|
if self.hvac_mode == HVACMode.HEAT_COOL:
|
||||||
return self._econet.heat_set_point
|
return self._econet.heat_set_point
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def target_temperature_high(self):
|
def target_temperature_high(self) -> int | None:
|
||||||
"""Return the higher bound temperature we try to reach."""
|
"""Return the higher bound temperature we try to reach."""
|
||||||
if self.hvac_mode == HVACMode.HEAT_COOL:
|
if self.hvac_mode == HVACMode.HEAT_COOL:
|
||||||
return self._econet.cool_set_point
|
return self._econet.cool_set_point
|
||||||
@ -142,7 +146,7 @@ class EcoNetThermostat(EcoNetEntity, ClimateEntity):
|
|||||||
self._econet.set_set_point(None, target_temp_high, target_temp_low)
|
self._econet.set_set_point(None, target_temp_high, target_temp_low)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_aux_heat(self):
|
def is_aux_heat(self) -> bool:
|
||||||
"""Return true if aux heater."""
|
"""Return true if aux heater."""
|
||||||
return self._econet.mode == ThermostatOperationMode.EMERGENCY_HEAT
|
return self._econet.mode == ThermostatOperationMode.EMERGENCY_HEAT
|
||||||
|
|
||||||
@ -171,7 +175,7 @@ class EcoNetThermostat(EcoNetEntity, ClimateEntity):
|
|||||||
self._econet.set_dehumidifier_set_point(humidity)
|
self._econet.set_dehumidifier_set_point(humidity)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fan_mode(self):
|
def fan_mode(self) -> str:
|
||||||
"""Return the current fan mode."""
|
"""Return the current fan mode."""
|
||||||
econet_fan_mode = self._econet.fan_mode
|
econet_fan_mode = self._econet.fan_mode
|
||||||
|
|
||||||
@ -185,7 +189,7 @@ class EcoNetThermostat(EcoNetEntity, ClimateEntity):
|
|||||||
return _current_fan_mode
|
return _current_fan_mode
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fan_modes(self):
|
def fan_modes(self) -> list[str]:
|
||||||
"""Return the fan modes."""
|
"""Return the fan modes."""
|
||||||
return [
|
return [
|
||||||
ECONET_FAN_STATE_TO_HA[mode]
|
ECONET_FAN_STATE_TO_HA[mode]
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
"""Support for EcoNet products."""
|
"""Support for EcoNet products."""
|
||||||
|
|
||||||
|
from pyeconet.equipment import Equipment
|
||||||
|
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
@ -8,18 +10,18 @@ from homeassistant.helpers.entity import Entity
|
|||||||
from .const import DOMAIN, PUSH_UPDATE
|
from .const import DOMAIN, PUSH_UPDATE
|
||||||
|
|
||||||
|
|
||||||
class EcoNetEntity(Entity):
|
class EcoNetEntity[_EquipmentT: Equipment = Equipment](Entity):
|
||||||
"""Define a base EcoNet entity."""
|
"""Define a base EcoNet entity."""
|
||||||
|
|
||||||
_attr_should_poll = False
|
_attr_should_poll = False
|
||||||
|
|
||||||
def __init__(self, econet):
|
def __init__(self, econet: _EquipmentT) -> None:
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
self._econet = econet
|
self._econet = econet
|
||||||
self._attr_name = econet.device_name
|
self._attr_name = econet.device_name
|
||||||
self._attr_unique_id = f"{econet.device_id}_{econet.device_name}"
|
self._attr_unique_id = f"{econet.device_id}_{econet.device_name}"
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Subscribe to device events."""
|
"""Subscribe to device events."""
|
||||||
await super().async_added_to_hass()
|
await super().async_added_to_hass()
|
||||||
self.async_on_remove(
|
self.async_on_remove(
|
||||||
@ -27,12 +29,12 @@ class EcoNetEntity(Entity):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def on_update_received(self):
|
def on_update_received(self) -> None:
|
||||||
"""Update was pushed from the ecoent API."""
|
"""Update was pushed from the ecoent API."""
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self):
|
def available(self) -> bool:
|
||||||
"""Return if the device is online or not."""
|
"""Return if the device is online or not."""
|
||||||
return self._econet.connected
|
return self._econet.connected
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ import logging
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from pyeconet.equipment import EquipmentType
|
from pyeconet.equipment import EquipmentType
|
||||||
from pyeconet.equipment.thermostat import ThermostatOperationMode
|
from pyeconet.equipment.thermostat import Thermostat, ThermostatOperationMode
|
||||||
|
|
||||||
from homeassistant.components.switch import SwitchEntity
|
from homeassistant.components.switch import SwitchEntity
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
@ -31,10 +31,10 @@ async def async_setup_entry(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class EcoNetSwitchAuxHeatOnly(EcoNetEntity, SwitchEntity):
|
class EcoNetSwitchAuxHeatOnly(EcoNetEntity[Thermostat], SwitchEntity):
|
||||||
"""Representation of a aux_heat_only EcoNet switch."""
|
"""Representation of a aux_heat_only EcoNet switch."""
|
||||||
|
|
||||||
def __init__(self, thermostat) -> None:
|
def __init__(self, thermostat: Thermostat) -> None:
|
||||||
"""Initialize EcoNet ventilator platform."""
|
"""Initialize EcoNet ventilator platform."""
|
||||||
super().__init__(thermostat)
|
super().__init__(thermostat)
|
||||||
self._attr_name = f"{thermostat.device_name} emergency heat"
|
self._attr_name = f"{thermostat.device_name} emergency heat"
|
||||||
|
@ -5,7 +5,7 @@ import logging
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from pyeconet.equipment import EquipmentType
|
from pyeconet.equipment import EquipmentType
|
||||||
from pyeconet.equipment.water_heater import WaterHeaterOperationMode
|
from pyeconet.equipment.water_heater import WaterHeater, WaterHeaterOperationMode
|
||||||
|
|
||||||
from homeassistant.components.water_heater import (
|
from homeassistant.components.water_heater import (
|
||||||
STATE_ECO,
|
STATE_ECO,
|
||||||
@ -61,24 +61,24 @@ async def async_setup_entry(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class EcoNetWaterHeater(EcoNetEntity, WaterHeaterEntity):
|
class EcoNetWaterHeater(EcoNetEntity[WaterHeater], WaterHeaterEntity):
|
||||||
"""Define an Econet water heater."""
|
"""Define an Econet water heater."""
|
||||||
|
|
||||||
_attr_should_poll = True # Override False default from EcoNetEntity
|
_attr_should_poll = True # Override False default from EcoNetEntity
|
||||||
_attr_temperature_unit = UnitOfTemperature.FAHRENHEIT
|
_attr_temperature_unit = UnitOfTemperature.FAHRENHEIT
|
||||||
|
|
||||||
def __init__(self, water_heater):
|
def __init__(self, water_heater: WaterHeater) -> None:
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
super().__init__(water_heater)
|
super().__init__(water_heater)
|
||||||
self.water_heater = water_heater
|
self.water_heater = water_heater
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_away_mode_on(self):
|
def is_away_mode_on(self) -> bool:
|
||||||
"""Return true if away mode is on."""
|
"""Return true if away mode is on."""
|
||||||
return self._econet.away
|
return self._econet.away
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_operation(self):
|
def current_operation(self) -> str:
|
||||||
"""Return current operation."""
|
"""Return current operation."""
|
||||||
econet_mode = self.water_heater.mode
|
econet_mode = self.water_heater.mode
|
||||||
_current_op = STATE_OFF
|
_current_op = STATE_OFF
|
||||||
@ -88,7 +88,7 @@ class EcoNetWaterHeater(EcoNetEntity, WaterHeaterEntity):
|
|||||||
return _current_op
|
return _current_op
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def operation_list(self):
|
def operation_list(self) -> list[str]:
|
||||||
"""List of available operation modes."""
|
"""List of available operation modes."""
|
||||||
econet_modes = self.water_heater.modes
|
econet_modes = self.water_heater.modes
|
||||||
op_list = []
|
op_list = []
|
||||||
@ -131,7 +131,7 @@ class EcoNetWaterHeater(EcoNetEntity, WaterHeaterEntity):
|
|||||||
_LOGGER.error("Invalid operation mode: %s", operation_mode)
|
_LOGGER.error("Invalid operation mode: %s", operation_mode)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def target_temperature(self):
|
def target_temperature(self) -> int:
|
||||||
"""Return the temperature we try to reach."""
|
"""Return the temperature we try to reach."""
|
||||||
return self.water_heater.set_point
|
return self.water_heater.set_point
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user