Changes for new FilterState construct
parent
ba836c2e36
commit
f4ef8fd1bc
|
@ -364,25 +364,24 @@ class RangeFilter(Filter):
|
|||
|
||||
def _filter_state(self, new_state):
|
||||
"""Implement the range filter."""
|
||||
new_state = float(new_state)
|
||||
|
||||
if new_state > self._upper_bound:
|
||||
if new_state.state > self._upper_bound:
|
||||
|
||||
self._stats_internal['erasures_up'] += 1
|
||||
|
||||
_LOGGER.debug("Upper outlier nr. %s in %s: %s",
|
||||
self._stats_internal['erasures_up'],
|
||||
self._entity, new_state)
|
||||
return self._upper_bound
|
||||
new_state.state = self._upper_bound
|
||||
|
||||
if new_state < self._lower_bound:
|
||||
elif new_state < self._lower_bound:
|
||||
|
||||
self._stats_internal['erasures_low'] += 1
|
||||
|
||||
_LOGGER.debug("Lower outlier nr. %s in %s: %s",
|
||||
self._stats_internal['erasures_low'],
|
||||
self._entity, new_state)
|
||||
return self._lower_bound
|
||||
new_state.state = self._upper_bound
|
||||
|
||||
return new_state
|
||||
|
||||
|
|
|
@ -140,14 +140,14 @@ class TestFilterSensor(unittest.TestCase):
|
|||
entity=None,
|
||||
lower_bound=lower,
|
||||
upper_bound=upper)
|
||||
for state in self.values:
|
||||
filtered = filt.filter_state(state)
|
||||
if state < lower:
|
||||
self.assertEqual(lower, filtered)
|
||||
elif state > upper:
|
||||
self.assertEqual(upper, filtered)
|
||||
for unf_state in self.values:
|
||||
filtered = filt.filter_state(unf_state)
|
||||
if unf_state.state < lower:
|
||||
self.assertEqual(lower, filtered.state)
|
||||
elif unf_state.state > upper:
|
||||
self.assertEqual(upper, filtered.state)
|
||||
else:
|
||||
self.assertEqual(state, filtered)
|
||||
self.assertEqual(unf_state.state, filtered.state)
|
||||
|
||||
def test_throttle(self):
|
||||
"""Test if lowpass filter works."""
|
||||
|
|
Loading…
Reference in New Issue