mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Setup geo_location to only track the geo_location domain (#41254)
The trigger was watching for all states
This commit is contained in:
parent
c3eb56c592
commit
15ade1232e
@ -2,16 +2,11 @@
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.geo_location import DOMAIN
|
from homeassistant.components.geo_location import DOMAIN
|
||||||
from homeassistant.const import (
|
from homeassistant.const import CONF_EVENT, CONF_PLATFORM, CONF_SOURCE, CONF_ZONE
|
||||||
CONF_EVENT,
|
|
||||||
CONF_PLATFORM,
|
|
||||||
CONF_SOURCE,
|
|
||||||
CONF_ZONE,
|
|
||||||
EVENT_STATE_CHANGED,
|
|
||||||
)
|
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers import condition, config_validation as cv
|
from homeassistant.helpers import condition, config_validation as cv
|
||||||
from homeassistant.helpers.config_validation import entity_domain
|
from homeassistant.helpers.config_validation import entity_domain
|
||||||
|
from homeassistant.helpers.event import TrackStates, async_track_state_change_filtered
|
||||||
|
|
||||||
# mypy: allow-untyped-defs, no-check-untyped-defs
|
# mypy: allow-untyped-defs, no-check-untyped-defs
|
||||||
|
|
||||||
@ -45,9 +40,6 @@ async def async_attach_trigger(hass, config, action, automation_info):
|
|||||||
@callback
|
@callback
|
||||||
def state_change_listener(event):
|
def state_change_listener(event):
|
||||||
"""Handle specific state changes."""
|
"""Handle specific state changes."""
|
||||||
# Skip if the event is not a geo_location entity.
|
|
||||||
if not event.data.get("entity_id").startswith(DOMAIN):
|
|
||||||
return
|
|
||||||
# Skip if the event's source does not match the trigger's source.
|
# Skip if the event's source does not match the trigger's source.
|
||||||
from_state = event.data.get("old_state")
|
from_state = event.data.get("old_state")
|
||||||
to_state = event.data.get("new_state")
|
to_state = event.data.get("new_state")
|
||||||
@ -83,4 +75,6 @@ async def async_attach_trigger(hass, config, action, automation_info):
|
|||||||
event.context,
|
event.context,
|
||||||
)
|
)
|
||||||
|
|
||||||
return hass.bus.async_listen(EVENT_STATE_CHANGED, state_change_listener)
|
return async_track_state_change_filtered(
|
||||||
|
hass, TrackStates(False, set(), {DOMAIN}), state_change_listener
|
||||||
|
).async_remove
|
||||||
|
Loading…
x
Reference in New Issue
Block a user