mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Bugfix trigger state with multible entities (#10857)
* Bugfix trigger state with multible entities * Fix numeric state * fix lint * fix dict * fix unsub * fix logic * fix name * fix new logic * add test for state * add numeric state test for unsub * add test for multible entities * Update numeric_state.py * Update numeric_state.py * Update state.py * Fix logic for triple match * Add clear to numeric state * clear for state trigger
This commit is contained in:
@@ -35,13 +35,11 @@ def async_trigger(hass, config, action):
|
||||
to_state = config.get(CONF_TO, MATCH_ALL)
|
||||
time_delta = config.get(CONF_FOR)
|
||||
match_all = (from_state == MATCH_ALL and to_state == MATCH_ALL)
|
||||
async_remove_track_same = None
|
||||
unsub_track_same = {}
|
||||
|
||||
@callback
|
||||
def state_automation_listener(entity, from_s, to_s):
|
||||
"""Listen for state changes and calls action."""
|
||||
nonlocal async_remove_track_same
|
||||
|
||||
@callback
|
||||
def call_action():
|
||||
"""Call action with right context."""
|
||||
@@ -64,7 +62,7 @@ def async_trigger(hass, config, action):
|
||||
call_action()
|
||||
return
|
||||
|
||||
async_remove_track_same = async_track_same_state(
|
||||
unsub_track_same[entity] = async_track_same_state(
|
||||
hass, time_delta, call_action,
|
||||
lambda _, _2, to_state: to_state.state == to_s.state,
|
||||
entity_ids=entity_id)
|
||||
@@ -76,7 +74,8 @@ def async_trigger(hass, config, action):
|
||||
def async_remove():
|
||||
"""Remove state listeners async."""
|
||||
unsub()
|
||||
if async_remove_track_same:
|
||||
async_remove_track_same() # pylint: disable=not-callable
|
||||
for async_remove in unsub_track_same.values():
|
||||
async_remove()
|
||||
unsub_track_same.clear()
|
||||
|
||||
return async_remove
|
||||
|
||||
Reference in New Issue
Block a user