Fix probability_threshold in binary_sensor.bayesian (#14512) (Closes: #14362)

This commit is contained in:
Diogo Gomes 2018-05-18 06:48:16 +01:00 committed by Sebastian Muszynski
parent a3777c4ea8
commit 97076aa3fd
2 changed files with 32 additions and 1 deletions

View file

@ -217,4 +217,4 @@ class BayesianBinarySensor(BinarySensorDevice):
@asyncio.coroutine
def async_update(self):
"""Get the latest data and update the states."""
self._deviation = bool(self.probability > self._probability_threshold)
self._deviation = bool(self.probability >= self._probability_threshold)

View file

@ -154,6 +154,37 @@ class TestBayesianBinarySensor(unittest.TestCase):
assert state.state == 'off'
def test_threshold(self):
"""Test sensor on probabilty threshold limits."""
config = {
'binary_sensor': {
'name':
'Test_Binary',
'platform':
'bayesian',
'observations': [{
'platform': 'state',
'entity_id': 'sensor.test_monitored',
'to_state': 'on',
'prob_given_true': 1.0,
}],
'prior':
0.5,
'probability_threshold':
1.0,
}
}
assert setup_component(self.hass, 'binary_sensor', config)
self.hass.states.set('sensor.test_monitored', 'on')
self.hass.block_till_done()
state = self.hass.states.get('binary_sensor.test_binary')
self.assertAlmostEqual(1.0, state.attributes.get('probability'))
assert state.state == 'on'
def test_multiple_observations(self):
"""Test sensor with multiple observations of same entity."""
config = {