Fix class attributes and instance attributes mixing

This commit is contained in:
Jean-Marc Collin
2024-11-25 23:17:53 +00:00
parent 4488c6e55c
commit 5793700261
7 changed files with 47 additions and 55 deletions

View File

@@ -56,7 +56,6 @@ class VersatileThermostatBaseConfigFlow(FlowHandler):
VERSION = CONFIG_VERSION
MINOR_VERSION = CONFIG_MINOR_VERSION
_infos: dict
_placeholders = {
CONF_NAME: "",
}
@@ -64,7 +63,7 @@ class VersatileThermostatBaseConfigFlow(FlowHandler):
def __init__(self, infos) -> None:
super().__init__()
_LOGGER.debug("CTOR BaseConfigFlow infos: %s", infos)
self._infos = infos
self._infos: dict = infos
# VTherm API should have been initialized before arriving here
vtherm_api = VersatileThermostatAPI.get_vtherm_api()

View File

@@ -26,20 +26,14 @@ MIN_NB_POINT = 4 # do not calculate slope until we have enough point
class WindowOpenDetectionAlgorithm:
"""The class that implements the algorithm listed above"""
_alert_threshold: float
_end_alert_threshold: float
_last_slope: float
_last_datetime: datetime
_last_temperature: float
_nb_point: int
def __init__(self, alert_threshold, end_alert_threshold) -> None:
"""Initalize a new algorithm with the both threshold"""
self._alert_threshold = alert_threshold
self._end_alert_threshold = end_alert_threshold
self._last_slope = None
self._last_datetime = None
self._nb_point = 0
self._alert_threshold: float = alert_threshold
self._end_alert_threshold: float = end_alert_threshold
self._last_slope: float | None = None
self._last_datetime: datetime = None
self._last_temperature: float | None = None
self._nb_point: int = 0
def check_age_last_measurement(self, temperature, datetime_now) -> float:
""" " Check if last measurement is old and add

View File

@@ -42,24 +42,6 @@ HVAC_ACTION_ON = [ # pylint: disable=invalid-name
class ThermostatOverClimate(BaseThermostat[UnderlyingClimate]):
"""Representation of a base class for a Versatile Thermostat over a climate"""
_auto_regulation_mode: str | None = None
_regulation_algo = None
_regulated_target_temp: float | None = None
_auto_regulation_dtemp: float | None = None
_auto_regulation_period_min: int | None = None
_last_regulation_change: datetime | None = None
# The fan mode configured in configEntry
_auto_fan_mode: str | None = None
# The current fan mode (could be change by service call)
_current_auto_fan_mode: str | None = None
# The fan_mode name depending of the current_mode
_auto_activated_fan_mode: str | None = None
_auto_deactivated_fan_mode: str | None = None
_auto_start_stop_level: TYPE_AUTO_START_STOP_LEVELS = AUTO_START_STOP_LEVEL_NONE
_auto_start_stop_algo: AutoStartStopDetectionAlgorithm | None = None
_is_auto_start_stop_enabled: bool = False
_follow_underlying_temp_change: bool = False
_entity_component_unrecorded_attributes = BaseThermostat._entity_component_unrecorded_attributes.union( # pylint: disable=protected-access
frozenset(
{
@@ -87,10 +69,30 @@ class ThermostatOverClimate(BaseThermostat[UnderlyingClimate]):
self, hass: HomeAssistant, unique_id: str, name: str, entry_infos: ConfigData
):
"""Initialize the thermostat over switch."""
self._auto_regulation_mode: str | None = None
self._regulation_algo = None
self._regulated_target_temp: float | None = None
self._auto_regulation_dtemp: float | None = None
self._auto_regulation_period_min: int | None = None
self._last_regulation_change: datetime | None = None
# The fan mode configured in configEntry
self._auto_fan_mode: str | None = None
# The current fan mode (could be change by service call)
self._current_auto_fan_mode: str | None = None
# The fan_mode name depending of the current_mode
self._auto_activated_fan_mode: str | None = None
self._auto_deactivated_fan_mode: str | None = None
self._auto_start_stop_level: TYPE_AUTO_START_STOP_LEVELS = (
AUTO_START_STOP_LEVEL_NONE
)
self._auto_start_stop_algo: AutoStartStopDetectionAlgorithm | None = None
self._is_auto_start_stop_enabled: bool = False
self._follow_underlying_temp_change: bool = False
self._last_regulation_change = None # NowClass.get_now(hass)
# super.__init__ calls post_init at the end. So it must be called after regulation initialization
super().__init__(hass, unique_id, name, entry_infos)
self._regulated_target_temp = self.target_temperature
self._last_regulation_change = None # NowClass.get_now(hass)
@overrides
def post_init(self, config_entry: ConfigData):

View File

@@ -40,17 +40,18 @@ class ThermostatOverClimateValve(ThermostatOverClimate):
}
)
)
_underlyings_valve_regulation: list[UnderlyingValveRegulation] = []
_valve_open_percent: int | None = None
_last_calculation_timestamp: datetime | None = None
_auto_regulation_dpercent: float | None = None
_auto_regulation_period_min: int | None = None
def __init__(
self, hass: HomeAssistant, unique_id: str, name: str, entry_infos: ConfigData
):
"""Initialize the ThermostatOverClimateValve class"""
_LOGGER.debug("%s - creating a ThermostatOverClimateValve VTherm", name)
self._underlyings_valve_regulation: list[UnderlyingValveRegulation] = []
self._valve_open_percent: int | None = None
self._last_calculation_timestamp: datetime | None = None
self._auto_regulation_dpercent: float | None = None
self._auto_regulation_period_min: int | None = None
super().__init__(hass, unique_id, name, entry_infos)
@overrides

View File

@@ -7,6 +7,7 @@ from homeassistant.helpers.event import (
async_track_state_change_event,
EventStateChangedData,
)
from homeassistant.core import HomeAssistant
from homeassistant.components.climate import HVACMode
from .const import (
@@ -45,11 +46,10 @@ class ThermostatOverSwitch(BaseThermostat[UnderlyingSwitch]):
)
)
# useless for now
# def __init__(self, hass: HomeAssistant, unique_id, name, config_entry) -> None:
# """Initialize the thermostat over switch."""
# super().__init__(hass, unique_id, name, config_entry)
_is_inversed: bool | None = None
def __init__(self, hass: HomeAssistant, unique_id, name, config_entry) -> None:
"""Initialize the thermostat over switch."""
self._is_inversed: bool | None = None
super().__init__(hass, unique_id, name, config_entry)
@property
def is_over_switch(self) -> bool:

View File

@@ -1021,10 +1021,6 @@ class UnderlyingValve(UnderlyingEntity):
class UnderlyingValveRegulation(UnderlyingValve):
"""A specific underlying class for Valve regulation"""
_offset_calibration_entity_id: str
_opening_degree_entity_id: str
_closing_degree_entity_id: str
def __init__(
self,
hass: HomeAssistant,
@@ -1041,14 +1037,14 @@ class UnderlyingValveRegulation(UnderlyingValve):
opening_degree_entity_id,
entity_type=UnderlyingEntityType.VALVE_REGULATION,
)
self._offset_calibration_entity_id = offset_calibration_entity_id
self._opening_degree_entity_id = opening_degree_entity_id
self._closing_degree_entity_id = closing_degree_entity_id
self._offset_calibration_entity_id: str = offset_calibration_entity_id
self._opening_degree_entity_id: str = opening_degree_entity_id
self._closing_degree_entity_id: str = closing_degree_entity_id
self._climate_underlying = climate_underlying
self._is_min_max_initialized = False
self._max_opening_degree = None
self._min_offset_calibration = None
self._max_offset_calibration = None
self._is_min_max_initialized: bool = False
self._max_opening_degree: float = None
self._min_offset_calibration: float = None
self._max_offset_calibration: float = None
async def send_percent_open(self):
"""Send the percent open to the underlying valve"""

View File

@@ -21,7 +21,7 @@ logging.getLogger().setLevel(logging.DEBUG)
# @pytest.mark.parametrize("expected_lingering_tasks", [True])
# @pytest.mark.parametrize("expected_lingering_timers", [True])
# this test fails if run in // with the next because the underlying_valve_regulation is mixed. Don't know why
@pytest.mark.skip
# @pytest.mark.skip
async def test_over_climate_valve_mono(hass: HomeAssistant, skip_hass_states_get):
"""Test the normal full start of a thermostat in thermostat_over_climate type"""