Skip to content

Commit

Permalink
Don't store datetime of fake datapoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Marc Collin committed Dec 1, 2023
1 parent 6ff4203 commit ca52c28
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions custom_components/versatile_thermostat/open_window_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ def check_age_last_measurement(self, temperature, datetime_now) -> float:

delta_t_sec = float((datetime_now - self._last_datetime).total_seconds()) / 60.0
if delta_t_sec >= MAX_DURATION_MIN:
return self.add_temp_measurement(temperature, datetime_now)
return self.add_temp_measurement(temperature, datetime_now, False)
else:
# do nothing
return self._last_slope

def add_temp_measurement(
self, temperature: float, datetime_measure: datetime
self, temperature: float, datetime_measure: datetime, store_date: bool = True
) -> float:
"""Add a new temperature measurement
returns the last slope
Expand Down Expand Up @@ -98,7 +98,11 @@ def add_temp_measurement(
else:
self._last_slope = round((0.2 * self._last_slope) + (0.8 * new_slope), 4)

self._last_datetime = datetime_measure
# if we are in cycle check and so adding a fake datapoint, we don't store the event datetime
# so that, when we will receive a real temperature point we will not calculate a wrong slope
if store_date:
self._last_datetime = datetime_measure

self._last_temperature = temperature

self._nb_point = self._nb_point + 1
Expand Down

0 comments on commit ca52c28

Please sign in to comment.