track_state_change now accepts a list of entity_ids
This commit is contained in:
parent
1e136a2416
commit
222d57bda7
3 changed files with 10 additions and 9 deletions
|
@ -106,16 +106,20 @@ class HomeAssistant(object):
|
|||
else:
|
||||
return self.states.entity_ids
|
||||
|
||||
def track_state_change(self, entity_id, action,
|
||||
def track_state_change(self, entity_ids, action,
|
||||
from_state=None, to_state=None):
|
||||
""" Track specific state changes. """
|
||||
from_state = _process_match_param(from_state)
|
||||
to_state = _process_match_param(to_state)
|
||||
|
||||
# Ensure it is a list with entity ids we want to match on
|
||||
if isinstance(entity_ids, str):
|
||||
entity_ids = [entity_ids]
|
||||
|
||||
@ft.wraps(action)
|
||||
def state_listener(event):
|
||||
""" The listener that listens for specific state changes. """
|
||||
if entity_id == event.data['entity_id'] and \
|
||||
if event.data['entity_id'] in entity_ids and \
|
||||
'old_state' in event.data and \
|
||||
_matcher(event.data['old_state'].state, from_state) and \
|
||||
_matcher(event.data['new_state'].state, to_state):
|
||||
|
|
|
@ -151,11 +151,9 @@ def setup(hass, config):
|
|||
|
||||
light.turn_off(hass)
|
||||
|
||||
# Track home coming of each seperate device
|
||||
for entity in device_entity_ids:
|
||||
hass.track_state_change(entity, check_light_on_dev_state_change,
|
||||
components.STATE_NOT_HOME,
|
||||
components.STATE_HOME)
|
||||
# Track home coming of each device
|
||||
hass.track_state_change(device_entity_ids, check_light_on_dev_state_change,
|
||||
components.STATE_NOT_HOME, components.STATE_HOME)
|
||||
|
||||
# Track when all devices are gone to shut down lights
|
||||
hass.track_state_change(device_tracker.ENTITY_ID_ALL_DEVICES,
|
||||
|
|
|
@ -186,8 +186,7 @@ def setup_group(hass, name, entity_ids, user_defined=True):
|
|||
if entity_id != ent_id]):
|
||||
hass.states.set(group_entity_id, group_off, state_attr)
|
||||
|
||||
for entity_id in entity_ids:
|
||||
hass.track_state_change(entity_id, update_group_state)
|
||||
hass.track_state_change(entity_ids, update_group_state)
|
||||
|
||||
hass.states.set(group_entity_id, group_state, state_attr)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue