From 5063374b973ea09a8525ad3c4a9bccbd0400c9f9 Mon Sep 17 00:00:00 2001 From: Jean-Marc Collin Date: Thu, 31 Oct 2024 22:29:30 +0000 Subject: [PATCH] Allow calculation even if slope is None --- .../auto_start_stop_algorithm.py | 13 ++++--------- .../versatile_thermostat/thermostat_climate.py | 14 +++++++------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/custom_components/versatile_thermostat/auto_start_stop_algorithm.py b/custom_components/versatile_thermostat/auto_start_stop_algorithm.py index 7ec35ba..d52ac8b 100644 --- a/custom_components/versatile_thermostat/auto_start_stop_algorithm.py +++ b/custom_components/versatile_thermostat/auto_start_stop_algorithm.py @@ -79,7 +79,7 @@ class AutoStartStopDetectionAlgorithm: saved_hvac_mode: HVACMode | None, target_temp: float, current_temp: float, - slope_min: float, + slope_min: float | None, now: datetime, ) -> AUTO_START_STOP_ACTIONS: """Calculate an eventual action to do depending of the value in parameter""" @@ -101,12 +101,7 @@ class AutoStartStopDetectionAlgorithm: now, ) - if ( - hvac_mode is None - or target_temp is None - or current_temp is None - or slope_min is None - ): + if hvac_mode is None or target_temp is None or current_temp is None: _LOGGER.debug( "%s - No all mandatory parameters are set. Disable auto-start/stop", self, @@ -119,8 +114,8 @@ class AutoStartStopDetectionAlgorithm: # reduce the error considering the dt between the last measurement if self._last_calculation_date is not None: dtmin = (now - self._last_calculation_date).total_seconds() / CYCLE_SEC - # ignore two calls too near (< 1 min) - if dtmin <= 0.5: + # ignore two calls too near (< 24 sec) + if dtmin <= 0.2: _LOGGER.debug( "%s - new calculation of auto_start_stop (%s) is too near of the last one (%s). Forget it", self, diff --git a/custom_components/versatile_thermostat/thermostat_climate.py b/custom_components/versatile_thermostat/thermostat_climate.py index d325d3f..a8953ad 100644 --- a/custom_components/versatile_thermostat/thermostat_climate.py +++ b/custom_components/versatile_thermostat/thermostat_climate.py @@ -912,16 +912,16 @@ class ThermostatOverClimate(BaseThermostat[UnderlyingClimate]): ret = await super().async_control_heating(force, _) # Check if we need to auto start/stop the Vtherm - if ( - self.auto_start_stop_enable - and self._window_auto_algo.last_slope is not None - ): + if self.auto_start_stop_enable: + slope = ( + self._window_auto_algo.last_slope or 0 + ) / 60 # to have the slope in °/min action = self._auto_start_stop_algo.calculate_action( self.hvac_mode, self._saved_hvac_mode, self.target_temperature, self.current_temperature, - self._window_auto_algo.last_slope / 60, # to have the slope in °/min + slope, self.now, ) _LOGGER.debug("%s - auto_start_stop action is %s", self, action) @@ -943,7 +943,7 @@ class ThermostatOverClimate(BaseThermostat[UnderlyingClimate]): "saved_hvac_mode": self._saved_hvac_mode, "target_temperature": self.target_temperature, "current_temperature": self.current_temperature, - "temperature_slope": self._window_auto_algo.last_slope, + "temperature_slope": slope, }, ) @@ -966,7 +966,7 @@ class ThermostatOverClimate(BaseThermostat[UnderlyingClimate]): "saved_hvac_mode": self._saved_hvac_mode, "target_temperature": self.target_temperature, "current_temperature": self.current_temperature, - "temperature_slope": self._window_auto_algo.last_slope, + "temperature_slope": slope, }, )