1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Fixes the sensor.filter outlier filter (handle step-changes correctly) (#21332)

* Fix outlier filter median return, Add/update filter outlier tests

* Switch outlier filter to store raw vals (handles step-changes correctly)

* Filter store_raw as attribute instead of filter_state parameter

* Fix linting issues
This commit is contained in:
siberx
2019-02-23 05:51:34 -08:00
committed by Diogo Gomes
parent 954bd4e13b
commit 616c7628d7
2 changed files with 28 additions and 5 deletions

View File

@@ -106,6 +106,23 @@ class TestFilterSensor(unittest.TestCase):
precision=2,
entity=None,
radius=4.0)
for state in self.values:
filtered = filt.filter_state(state)
assert 21 == filtered.state
def test_outlier_step(self):
"""
Test step-change handling in outlier.
Test if outlier filter handles long-running step-changes correctly.
It should converge to no longer filter once just over half the
window_size is occupied by the new post step-change values.
"""
filt = OutlierFilter(window_size=3,
precision=2,
entity=None,
radius=1.1)
self.values[-1].state = 22
for state in self.values:
filtered = filt.filter_state(state)
assert 22 == filtered.state
@@ -119,7 +136,7 @@ class TestFilterSensor(unittest.TestCase):
out = ha.State('sensor.test_monitored', 4000)
for state in [out]+self.values:
filtered = filt.filter_state(state)
assert 22 == filtered.state
assert 21 == filtered.state
def test_lowpass(self):
"""Test if lowpass filter works."""