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 authored and Diogo Gomes committed 2019-02-23 13:51:33 +00:00
1 parent 954bd4e13b
commit 616c7628d7
2 files changed
+28 -5

No files matched your search

+18 -1
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."""