Skip to content
Snippets Groups Projects
Unverified Commit c1aaceeb authored by J. Nick Koston's avatar J. Nick Koston Committed by GitHub
Browse files

Use async_track_state_change_event for automation numeric_state (#37255)

Calling async_track_state_change_event directly
is faster than async_track_state_change (see #37251) and has
slightly lower latency triggering state updates
parent 404b1f40
No related branches found
No related tags found
No related merge requests found
......@@ -14,7 +14,10 @@ from homeassistant.const import (
)
from homeassistant.core import CALLBACK_TYPE, callback
from homeassistant.helpers import condition, config_validation as cv, template
from homeassistant.helpers.event import async_track_same_state, async_track_state_change
from homeassistant.helpers.event import (
async_track_same_state,
async_track_state_change_event,
)
# mypy: allow-incomplete-defs, allow-untyped-calls, allow-untyped-defs
# mypy: no-check-untyped-defs
......@@ -94,8 +97,11 @@ async def async_attach_trigger(
)
@callback
def state_automation_listener(entity, from_s, to_s):
def state_automation_listener(event):
"""Listen for state changes and calls action."""
entity = event.data.get("entity_id")
from_s = event.data.get("old_state")
to_s = event.data.get("new_state")
@callback
def call_action():
......@@ -168,7 +174,7 @@ async def async_attach_trigger(
else:
call_action()
unsub = async_track_state_change(hass, entity_id, state_automation_listener)
unsub = async_track_state_change_event(hass, entity_id, state_automation_listener)
@callback
def async_remove():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment