Add hysteresis attribute to threshold binary sensor (#9596)

* Added hysteresis attribute to threshold binary sensor

* Added threshold binary sensor hysteresis test case

* Changed threshold binary sensor property name to be more self explanatory

* Pulled default hysteresis value into top level declaration

* Fixed linter errors

* Fixed additional linter errors

* Move comment to docs
This commit is contained in:
Sam Birch authored and Fabian Affolter committed 2017-10-02 17:15:19 +02:00
1 parent b4551cc127
commit da4048a9ec
2 files changed
+73 -11

No files matched your search

@@ -96,3 +96,53 @@ class TestThresholdSensor(unittest.TestCase):
state = self.hass.states.get('binary_sensor.test_threshold')
assert state.state == 'off'
def test_sensor_hysteresis(self):
"""Test if source is above threshold using hysteresis."""
config = {
'binary_sensor': {
'platform': 'threshold',
'threshold': '15',
'hysteresis': '2.5',
'name': 'Test_threshold',
'type': 'upper',
'entity_id': 'sensor.test_monitored',
}
}
assert setup_component(self.hass, 'binary_sensor', config)
self.hass.states.set('sensor.test_monitored', 20)
self.hass.block_till_done()
state = self.hass.states.get('binary_sensor.test_threshold')
assert state.state == 'on'
self.hass.states.set('sensor.test_monitored', 13)
self.hass.block_till_done()
state = self.hass.states.get('binary_sensor.test_threshold')
assert state.state == 'on'
self.hass.states.set('sensor.test_monitored', 12)
self.hass.block_till_done()
state = self.hass.states.get('binary_sensor.test_threshold')
assert state.state == 'off'
self.hass.states.set('sensor.test_monitored', 17)
self.hass.block_till_done()
state = self.hass.states.get('binary_sensor.test_threshold')
assert state.state == 'off'
self.hass.states.set('sensor.test_monitored', 18)
self.hass.block_till_done()
state = self.hass.states.get('binary_sensor.test_threshold')
assert state.state == 'on'