Fix rangefilter (#17473)

* Fix rangefilter

RangeFilter would break for lower or upper bounds of 0, evaluating to False and thus not being handled correctly as bounds

* Add test for zero bounds
This commit is contained in:
Niels Mündler authored and Pascal Vizeli committed 2018-10-15 12:24:21 +02:00
1 parent 373e3b12d8
commit d6752d2270
2 files changed
+22 -3

No files matched your search

+17
View File
@@ -149,6 +149,23 @@ class TestFilterSensor(unittest.TestCase):
else:
self.assertEqual(unf, filtered.state)
def test_range_zero(self):
"""Test if range filter works with zeroes as bounds."""
lower = 0
upper = 0
filt = RangeFilter(entity=None,
lower_bound=lower,
upper_bound=upper)
for unf_state in self.values:
unf = float(unf_state.state)
filtered = filt.filter_state(unf_state)
if unf < lower:
self.assertEqual(lower, filtered.state)
elif unf > upper:
self.assertEqual(upper, filtered.state)
else:
self.assertEqual(unf, filtered.state)
def test_throttle(self):
"""Test if lowpass filter works."""
filt = ThrottleFilter(window_size=3,