From 77c68cb50744a596ddfb9d07859bb2fa76b8f2ce Mon Sep 17 00:00:00 2001 From: Robert Hillis Date: Sun, 11 Jul 2021 16:37:41 -0400 Subject: [PATCH] Use entity class attributes for bayesian (#52831) --- .../components/bayesian/binary_sensor.py | 33 ++++--------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/homeassistant/components/bayesian/binary_sensor.py b/homeassistant/components/bayesian/binary_sensor.py index 6879e278bab..41654973ffe 100644 --- a/homeassistant/components/bayesian/binary_sensor.py +++ b/homeassistant/components/bayesian/binary_sensor.py @@ -129,13 +129,15 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= class BayesianBinarySensor(BinarySensorEntity): """Representation of a Bayesian sensor.""" + _attr_should_poll = False + def __init__(self, name, prior, observations, probability_threshold, device_class): """Initialize the Bayesian sensor.""" - self._name = name + self._attr_name = name self._observations = observations self._probability_threshold = probability_threshold - self._device_class = device_class - self._deviation = False + self._attr_device_class = device_class + self._attr_is_on = False self._callbacks = [] self.prior = prior @@ -238,12 +240,12 @@ class BayesianBinarySensor(BinarySensorEntity): self.current_observations.update(self._initialize_current_observations()) self.probability = self._calculate_new_probability() - self._deviation = bool(self.probability >= self._probability_threshold) + self._attr_is_on = bool(self.probability >= self._probability_threshold) @callback def _recalculate_and_write_state(self): self.probability = self._calculate_new_probability() - self._deviation = bool(self.probability >= self._probability_threshold) + self._attr_is_on = bool(self.probability >= self._probability_threshold) self.async_write_ha_state() def _initialize_current_observations(self): @@ -363,30 +365,9 @@ class BayesianBinarySensor(BinarySensorEntity): except ConditionError: return False - @property - def name(self): - """Return the name of the sensor.""" - return self._name - - @property - def is_on(self): - """Return true if sensor is on.""" - return self._deviation - - @property - def should_poll(self): - """No polling needed.""" - return False - - @property - def device_class(self): - """Return the sensor class of the sensor.""" - return self._device_class - @property def extra_state_attributes(self): """Return the state attributes of the sensor.""" - attr_observations_list = [ obs.copy() for obs in self.current_observations.values() if obs is not None ]