Skip to content

Commit

Permalink
Update to return a list without duplicates in the state attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
paolog89 committed Feb 20, 2020
1 parent 4888c13 commit 1dcbd57
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
11 changes: 8 additions & 3 deletions homeassistant/components/bayesian/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Use Bayesian Inference to trigger a binary sensor."""
from collections import OrderedDict
from itertools import chain

import voluptuous as vol

Expand Down Expand Up @@ -131,10 +132,10 @@ def __init__(self, name, prior, observations, probability_threshold, device_clas

for obs in self._observations:
if "entity_id" in obs:
self.entity_obs_dict.append(obs.get("entity_id"))
self.entity_obs_dict.append([obs.get("entity_id")])
if "value_template" in obs:
self.entity_obs_dict.append(
set(obs.get(CONF_VALUE_TEMPLATE).extract_entities())
list(obs.get(CONF_VALUE_TEMPLATE).extract_entities())
)

to_observe = set()
Expand Down Expand Up @@ -262,7 +263,11 @@ def device_state_attributes(self):
return {
ATTR_OBSERVATIONS: list(self.current_obs.values()),
ATTR_ENTITY_ID: list(
self.entity_obs_dict[obs] for obs in self.current_obs.keys()
set(
chain.from_iterable(
self.entity_obs_dict[obs] for obs in self.current_obs.keys()
)
)
),
ATTR_PROBABILITY: round(self.probability, 2),
ATTR_PROBABILITY_THRESHOLD: self._probability_threshold,
Expand Down
3 changes: 1 addition & 2 deletions tests/components/bayesian/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,5 @@ def test_observed_entities(self):

state = self.hass.states.get("binary_sensor.test_binary")
assert [
"sensor.test_monitored",
{"sensor.test_monitored1", "sensor.test_monitored"},
"sensor.test_monitored", "sensor.test_monitored1"
] == state.attributes.get("observed_entities")

0 comments on commit 1dcbd57

Please sign in to comment.