From 1ff9e03ca393c1872be3319a4d5ec919e1cfe4ce Mon Sep 17 00:00:00 2001 From: arsaboo Date: Sun, 10 Sep 2017 12:43:26 -0400 Subject: [PATCH 1/3] Round off probablity to 2 decimals. --- homeassistant/components/binary_sensor/bayesian.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/binary_sensor/bayesian.py b/homeassistant/components/binary_sensor/bayesian.py index 4c62735a6f9fbe..7c3e54de9dc0de 100644 --- a/homeassistant/components/binary_sensor/bayesian.py +++ b/homeassistant/components/binary_sensor/bayesian.py @@ -201,7 +201,7 @@ def device_state_attributes(self): """Return the state attributes of the sensor.""" return { 'observations': [val for val in self.current_obs.values()], - 'probability': self.probability, + 'probability': round(self.probability, 2), 'probability_threshold': self._probability_threshold } From 1767fa2f228aa46debef096bf41e20a8dad82b3f Mon Sep 17 00:00:00 2001 From: arsaboo Date: Sun, 10 Sep 2017 14:10:31 -0400 Subject: [PATCH 2/3] Update tests --- tests/components/binary_sensor/test_bayesian.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/components/binary_sensor/test_bayesian.py b/tests/components/binary_sensor/test_bayesian.py index f86047f3a3df47..61b110f247f099 100644 --- a/tests/components/binary_sensor/test_bayesian.py +++ b/tests/components/binary_sensor/test_bayesian.py @@ -73,7 +73,7 @@ def test_sensor_numeric_state(self): 'prob_false': 0.1, 'prob_true': 0.9 }], state.attributes.get('observations')) - self.assertAlmostEqual(0.7714285714285715, + self.assertAlmostEqual(0.77, state.attributes.get('probability')) assert state.state == 'on' @@ -141,7 +141,7 @@ def test_sensor_state(self): 'prob_true': 0.8, 'prob_false': 0.4 }], state.attributes.get('observations')) - self.assertAlmostEqual(0.33333333, state.attributes.get('probability')) + self.assertAlmostEqual(0.33, state.attributes.get('probability')) assert state.state == 'on' From c6293d35f17108890ee9230c6b243017b1aad1cb Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Mon, 11 Sep 2017 16:34:05 +0200 Subject: [PATCH 3/3] remove debug print --- homeassistant/components/binary_sensor/bayesian.py | 1 - 1 file changed, 1 deletion(-) diff --git a/homeassistant/components/binary_sensor/bayesian.py b/homeassistant/components/binary_sensor/bayesian.py index 7c3e54de9dc0de..ac328fd1f41e4c 100644 --- a/homeassistant/components/binary_sensor/bayesian.py +++ b/homeassistant/components/binary_sensor/bayesian.py @@ -126,7 +126,6 @@ def async_threshold_sensor_state_listener(entity, old_state, self.watchers[platform](entity_obs) prior = self.prior - print(self.current_obs.values()) for obs in self.current_obs.values(): prior = update_probability(prior, obs['prob_true'], obs['prob_false'])