mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Bugfix automation state linsteners (#6120)
* Bugfix automation state linsteners * address paulus comments. * fix lint * fix lint v2
This commit is contained in:
parent
11d3093a30
commit
8983b826c4
@ -45,6 +45,19 @@ def async_trigger(hass, config, action):
|
|||||||
async_remove_state_for_cancel = None
|
async_remove_state_for_cancel = None
|
||||||
async_remove_state_for_listener = None
|
async_remove_state_for_listener = None
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def clear_listener():
|
||||||
|
"""Clear all unsub listener."""
|
||||||
|
nonlocal async_remove_state_for_cancel, async_remove_state_for_listener
|
||||||
|
|
||||||
|
# pylint: disable=not-callable
|
||||||
|
if async_remove_state_for_listener is not None:
|
||||||
|
async_remove_state_for_listener()
|
||||||
|
async_remove_state_for_listener = None
|
||||||
|
if async_remove_state_for_cancel is not None:
|
||||||
|
async_remove_state_for_cancel()
|
||||||
|
async_remove_state_for_cancel = None
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def state_automation_listener(entity, from_s, to_s):
|
def state_automation_listener(entity, from_s, to_s):
|
||||||
"""Listen for state changes and calls action."""
|
"""Listen for state changes and calls action."""
|
||||||
@ -66,18 +79,11 @@ def async_trigger(hass, config, action):
|
|||||||
call_action()
|
call_action()
|
||||||
return
|
return
|
||||||
|
|
||||||
@callback
|
|
||||||
def clear_listener():
|
|
||||||
"""Clear all unsub listener."""
|
|
||||||
nonlocal async_remove_state_for_cancel
|
|
||||||
nonlocal async_remove_state_for_listener
|
|
||||||
async_remove_state_for_listener = None
|
|
||||||
async_remove_state_for_cancel = None
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def state_for_listener(now):
|
def state_for_listener(now):
|
||||||
"""Fire on state changes after a delay and calls action."""
|
"""Fire on state changes after a delay and calls action."""
|
||||||
async_remove_state_for_cancel()
|
nonlocal async_remove_state_for_listener
|
||||||
|
async_remove_state_for_listener = None
|
||||||
clear_listener()
|
clear_listener()
|
||||||
call_action()
|
call_action()
|
||||||
|
|
||||||
@ -86,10 +92,11 @@ def async_trigger(hass, config, action):
|
|||||||
"""Fire on changes and cancel for listener if changed."""
|
"""Fire on changes and cancel for listener if changed."""
|
||||||
if inner_to_s.state == to_s.state:
|
if inner_to_s.state == to_s.state:
|
||||||
return
|
return
|
||||||
async_remove_state_for_listener()
|
|
||||||
async_remove_state_for_cancel()
|
|
||||||
clear_listener()
|
clear_listener()
|
||||||
|
|
||||||
|
# cleanup previous listener
|
||||||
|
clear_listener()
|
||||||
|
|
||||||
async_remove_state_for_listener = async_track_point_in_utc_time(
|
async_remove_state_for_listener = async_track_point_in_utc_time(
|
||||||
hass, state_for_listener, dt_util.utcnow() + time_delta)
|
hass, state_for_listener, dt_util.utcnow() + time_delta)
|
||||||
|
|
||||||
@ -103,11 +110,6 @@ def async_trigger(hass, config, action):
|
|||||||
def async_remove():
|
def async_remove():
|
||||||
"""Remove state listeners async."""
|
"""Remove state listeners async."""
|
||||||
unsub()
|
unsub()
|
||||||
# pylint: disable=not-callable
|
clear_listener()
|
||||||
if async_remove_state_for_cancel is not None:
|
|
||||||
async_remove_state_for_cancel()
|
|
||||||
|
|
||||||
if async_remove_state_for_listener is not None:
|
|
||||||
async_remove_state_for_listener()
|
|
||||||
|
|
||||||
return async_remove
|
return async_remove
|
||||||
|
Loading…
x
Reference in New Issue
Block a user