From c7ecebfd07cc82ca6c3a40a8ec7e34b69cd64a60 Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Tue, 12 Sep 2017 00:44:51 +0530 Subject: [PATCH] Round off probability to 2 decimals. (#9365) * Round off probablity to 2 decimals. * Update tests * remove debug print --- homeassistant/components/binary_sensor/bayesian.py | 3 +-- tests/components/binary_sensor/test_bayesian.py | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/binary_sensor/bayesian.py b/homeassistant/components/binary_sensor/bayesian.py index 4c62735a6f9..ac328fd1f41 100644 --- a/homeassistant/components/binary_sensor/bayesian.py +++ b/homeassistant/components/binary_sensor/bayesian.py @@ -126,7 +126,6 @@ class BayesianBinarySensor(BinarySensorDevice): 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']) @@ -201,7 +200,7 @@ class BayesianBinarySensor(BinarySensorDevice): """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 } diff --git a/tests/components/binary_sensor/test_bayesian.py b/tests/components/binary_sensor/test_bayesian.py index f86047f3a3d..61b110f247f 100644 --- a/tests/components/binary_sensor/test_bayesian.py +++ b/tests/components/binary_sensor/test_bayesian.py @@ -73,7 +73,7 @@ class TestBayesianBinarySensor(unittest.TestCase): '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 @@ class TestBayesianBinarySensor(unittest.TestCase): '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'