Small collection of random styling tweaks, fixes and Pythonism (#35390)
This commit is contained in:
1 parent
3feb55a8e4
commit
4cf186a47e
14 files changed
+28
-57
No files matched your search
@@ -91,8 +91,7 @@ def update_probability(prior, prob_given_true, prob_given_false):
|
||||
"""Update probability using Bayes' rule."""
|
||||
numerator = prob_given_true * prior
|
||||
denominator = numerator + prob_given_false * (1 - prior)
|
||||
probability = numerator / denominator
|
||||
return probability
|
||||
return numerator / denominator
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
@@ -246,7 +245,7 @@ class BayesianBinarySensor(BinarySensorEntity):
|
||||
"""Return True if numeric condition is met."""
|
||||
entity = entity_observation["entity_id"]
|
||||
|
||||
should_trigger = condition.async_numeric_state(
|
||||
return condition.async_numeric_state(
|
||||
self.hass,
|
||||
entity,
|
||||
entity_observation.get("below"),
|
||||
@@ -254,26 +253,18 @@ class BayesianBinarySensor(BinarySensorEntity):
|
||||
None,
|
||||
entity_observation,
|
||||
)
|
||||
return should_trigger
|
||||
|
||||
def _process_state(self, entity_observation):
|
||||
"""Return True if state conditions are met."""
|
||||
entity = entity_observation["entity_id"]
|
||||
|
||||
should_trigger = condition.state(
|
||||
self.hass, entity, entity_observation.get("to_state")
|
||||
)
|
||||
|
||||
return should_trigger
|
||||
return condition.state(self.hass, entity, entity_observation.get("to_state"))
|
||||
|
||||
def _process_template(self, entity_observation):
|
||||
"""Return True if template condition is True."""
|
||||
template = entity_observation.get(CONF_VALUE_TEMPLATE)
|
||||
template.hass = self.hass
|
||||
should_trigger = condition.async_template(
|
||||
self.hass, template, entity_observation
|
||||
)
|
||||
return should_trigger
|
||||
return condition.async_template(self.hass, template, entity_observation)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
@@ -299,9 +290,9 @@ class BayesianBinarySensor(BinarySensorEntity):
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes of the sensor."""
|
||||
|
||||
attr_observations_list = list(
|
||||
attr_observations_list = [
|
||||
obs.copy() for obs in self.current_observations.values() if obs is not None
|
||||
)
|
||||
]
|
||||
|
||||
for item in attr_observations_list:
|
||||
item.pop("value_template", None)
|
||||
|
||||
Reference in new issue
Block a user