mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Fix moving average for 0 values (#80476)
This commit is contained in:
parent
1a274adc28
commit
f82c4c7633
@ -612,7 +612,7 @@ class TimeSMAFilter(Filter, SensorEntity):
|
|||||||
|
|
||||||
moving_sum = 0
|
moving_sum = 0
|
||||||
start = new_state.timestamp - self._time_window
|
start = new_state.timestamp - self._time_window
|
||||||
prev_state = self.last_leak or self.queue[0]
|
prev_state = self.last_leak if self.last_leak is not None else self.queue[0]
|
||||||
for state in self.queue:
|
for state in self.queue:
|
||||||
moving_sum += (state.timestamp - start).total_seconds() * prev_state.state
|
moving_sum += (state.timestamp - start).total_seconds() * prev_state.state
|
||||||
start = state.timestamp
|
start = state.timestamp
|
||||||
|
Loading…
x
Reference in New Issue
Block a user