Improve type hints in econet (#136693)

Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
pull/136706/head
epenet 2025-01-28 11:45:24 +01:00 committed by GitHub
parent d9d6308b78
commit f1305cd5a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 35 additions and 29 deletions

View File

@ -2,7 +2,7 @@
from __future__ import annotations
from pyeconet.equipment import EquipmentType
from pyeconet.equipment import Equipment, EquipmentType
from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
@ -63,7 +63,7 @@ class EcoNetBinarySensor(EcoNetEntity, BinarySensorEntity):
"""Define a Econet binary sensor."""
def __init__(
self, econet_device, description: BinarySensorEntityDescription
self, econet_device: Equipment, description: BinarySensorEntityDescription
) -> None:
"""Initialize."""
super().__init__(econet_device)

View File

@ -3,7 +3,11 @@
from typing import Any
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 (
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."""
_attr_should_poll = True
_attr_temperature_unit = UnitOfTemperature.FAHRENHEIT
def __init__(self, thermostat):
def __init__(self, thermostat: Thermostat) -> None:
"""Initialize."""
super().__init__(thermostat)
self._attr_hvac_modes = []
@ -92,24 +96,24 @@ class EcoNetThermostat(EcoNetEntity, ClimateEntity):
)
@property
def current_temperature(self):
def current_temperature(self) -> int:
"""Return the current temperature."""
return self._econet.set_point
@property
def current_humidity(self):
def current_humidity(self) -> int:
"""Return the current humidity."""
return self._econet.humidity
@property
def target_humidity(self):
def target_humidity(self) -> int | None:
"""Return the humidity we try to reach."""
if self._econet.supports_humidifier:
return self._econet.dehumidifier_set_point
return None
@property
def target_temperature(self):
def target_temperature(self) -> int | None:
"""Return the temperature we try to reach."""
if self.hvac_mode == HVACMode.COOL:
return self._econet.cool_set_point
@ -118,14 +122,14 @@ class EcoNetThermostat(EcoNetEntity, ClimateEntity):
return None
@property
def target_temperature_low(self):
def target_temperature_low(self) -> int | None:
"""Return the lower bound temperature we try to reach."""
if self.hvac_mode == HVACMode.HEAT_COOL:
return self._econet.heat_set_point
return None
@property
def target_temperature_high(self):
def target_temperature_high(self) -> int | None:
"""Return the higher bound temperature we try to reach."""
if self.hvac_mode == HVACMode.HEAT_COOL:
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)
@property
def is_aux_heat(self):
def is_aux_heat(self) -> bool:
"""Return true if aux heater."""
return self._econet.mode == ThermostatOperationMode.EMERGENCY_HEAT
@ -171,7 +175,7 @@ class EcoNetThermostat(EcoNetEntity, ClimateEntity):
self._econet.set_dehumidifier_set_point(humidity)
@property
def fan_mode(self):
def fan_mode(self) -> str:
"""Return the current fan mode."""
econet_fan_mode = self._econet.fan_mode
@ -185,7 +189,7 @@ class EcoNetThermostat(EcoNetEntity, ClimateEntity):
return _current_fan_mode
@property
def fan_modes(self):
def fan_modes(self) -> list[str]:
"""Return the fan modes."""
return [
ECONET_FAN_STATE_TO_HA[mode]

View File

@ -1,5 +1,7 @@
"""Support for EcoNet products."""
from pyeconet.equipment import Equipment
from homeassistant.core import callback
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.dispatcher import async_dispatcher_connect
@ -8,18 +10,18 @@ from homeassistant.helpers.entity import Entity
from .const import DOMAIN, PUSH_UPDATE
class EcoNetEntity(Entity):
class EcoNetEntity[_EquipmentT: Equipment = Equipment](Entity):
"""Define a base EcoNet entity."""
_attr_should_poll = False
def __init__(self, econet):
def __init__(self, econet: _EquipmentT) -> None:
"""Initialize."""
self._econet = econet
self._attr_name = 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."""
await super().async_added_to_hass()
self.async_on_remove(
@ -27,12 +29,12 @@ class EcoNetEntity(Entity):
)
@callback
def on_update_received(self):
def on_update_received(self) -> None:
"""Update was pushed from the ecoent API."""
self.async_write_ha_state()
@property
def available(self):
def available(self) -> bool:
"""Return if the device is online or not."""
return self._econet.connected

View File

@ -6,7 +6,7 @@ import logging
from typing import Any
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.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."""
def __init__(self, thermostat) -> None:
def __init__(self, thermostat: Thermostat) -> None:
"""Initialize EcoNet ventilator platform."""
super().__init__(thermostat)
self._attr_name = f"{thermostat.device_name} emergency heat"

View File

@ -5,7 +5,7 @@ import logging
from typing import Any
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 (
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."""
_attr_should_poll = True # Override False default from EcoNetEntity
_attr_temperature_unit = UnitOfTemperature.FAHRENHEIT
def __init__(self, water_heater):
def __init__(self, water_heater: WaterHeater) -> None:
"""Initialize."""
super().__init__(water_heater)
self.water_heater = water_heater
@property
def is_away_mode_on(self):
def is_away_mode_on(self) -> bool:
"""Return true if away mode is on."""
return self._econet.away
@property
def current_operation(self):
def current_operation(self) -> str:
"""Return current operation."""
econet_mode = self.water_heater.mode
_current_op = STATE_OFF
@ -88,7 +88,7 @@ class EcoNetWaterHeater(EcoNetEntity, WaterHeaterEntity):
return _current_op
@property
def operation_list(self):
def operation_list(self) -> list[str]:
"""List of available operation modes."""
econet_modes = self.water_heater.modes
op_list = []
@ -131,7 +131,7 @@ class EcoNetWaterHeater(EcoNetEntity, WaterHeaterEntity):
_LOGGER.error("Invalid operation mode: %s", operation_mode)
@property
def target_temperature(self):
def target_temperature(self) -> int:
"""Return the temperature we try to reach."""
return self.water_heater.set_point