From ab1c6892dfbb03e3f7adf17b2b095cf8d6c90d76 Mon Sep 17 00:00:00 2001 From: Jean-Marc Collin Date: Sun, 12 Nov 2023 09:20:52 +0000 Subject: [PATCH] Issue #164 - multiple calls to regulation --- .../thermostat_climate.py | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/custom_components/versatile_thermostat/thermostat_climate.py b/custom_components/versatile_thermostat/thermostat_climate.py index c138333..9a52bb3 100644 --- a/custom_components/versatile_thermostat/thermostat_climate.py +++ b/custom_components/versatile_thermostat/thermostat_climate.py @@ -115,9 +115,22 @@ class ThermostatOverClimate(BaseThermostat): force, ) + now: datetime = NowClass.get_now(self._hass) + period = float((now - self._last_regulation_change).total_seconds()) / 60.0 + if not force and period < self._auto_regulation_period_min: + _LOGGER.info( + "%s - period (%.1f) min is < %.0f min -> forget the regulation send", + self, + period, + self._auto_regulation_period_min, + ) + return + if not self._regulated_target_temp: self._regulated_target_temp = self.target_temperature + _LOGGER.info("%s - regulation calculation will be done", self) + new_regulated_temp = round_to_nearest( self._regulation_algo.calculate_regulated_temperature( self.current_temperature, self._cur_ext_temp @@ -127,7 +140,7 @@ class ThermostatOverClimate(BaseThermostat): dtemp = new_regulated_temp - self._regulated_target_temp if not force and abs(dtemp) < self._auto_regulation_dtemp: - _LOGGER.debug( + _LOGGER.info( "%s - dtemp (%.1f) is < %.1f -> forget the regulation send", self, dtemp, @@ -135,17 +148,6 @@ class ThermostatOverClimate(BaseThermostat): ) return - now: datetime = NowClass.get_now(self._hass) - period = float((now - self._last_regulation_change).total_seconds()) / 60.0 - if not force and period < self._auto_regulation_period_min: - _LOGGER.debug( - "%s - period (%.1f) is < %.0f -> forget the regulation send", - self, - period, - self._auto_regulation_period_min, - ) - return - self._regulated_target_temp = new_regulated_temp _LOGGER.info( "%s - Regulated temp have changed to %.1f. Resend it to underlyings",