diff --git a/custom_components/versatile_thermostat/pi_algorithm.py b/custom_components/versatile_thermostat/pi_algorithm.py index 859e7af..e36967e 100644 --- a/custom_components/versatile_thermostat/pi_algorithm.py +++ b/custom_components/versatile_thermostat/pi_algorithm.py @@ -48,7 +48,8 @@ class PITemperatureRegulator: """Set the new target_temp""" self.target_temp = target_temp # Do not reset the accumulated error - # self.accumulated_error = 0 + # Discussion #191. After a target change we should reset the accumulated error which is certainly wrong now. + self.accumulated_error = 0 def calculate_regulated_temperature( self, internal_temp: float, external_temp: float diff --git a/tests/test_auto_regulation.py b/tests/test_auto_regulation.py index aa21e0a..327c7f2 100644 --- a/tests/test_auto_regulation.py +++ b/tests/test_auto_regulation.py @@ -355,7 +355,7 @@ async def test_over_climate_regulation_limitations( await send_ext_temperature_change_event(entity, 10, event_timestamp) # the regulated temperature should be under - assert entity.regulated_target_temp == old_regulated_temp + assert entity.regulated_target_temp <= old_regulated_temp # change temperature so that dtemp > 0.5 and time is > period_min (+ 3min) event_timestamp = now - timedelta(minutes=12) @@ -363,12 +363,12 @@ async def test_over_climate_regulation_limitations( "custom_components.versatile_thermostat.commons.NowClass.get_now", return_value=event_timestamp, ): - await send_temperature_change_event(entity, 17, event_timestamp) + await send_temperature_change_event(entity, 16, event_timestamp) await send_ext_temperature_change_event(entity, 12, event_timestamp) # the regulated should have been done assert entity.regulated_target_temp != old_regulated_temp - assert entity.regulated_target_temp > entity.target_temperature + assert entity.regulated_target_temp >= entity.target_temperature assert ( entity.regulated_target_temp == 17 + 0.5 ) # 0.7 without round_to_nearest