Setup geo_location to only track the geo_location domain (#41254)

The trigger was watching for all states
This commit is contained in:
J. Nick Koston 2020-10-05 07:25:41 -05:00 committed by GitHub
parent c3eb56c592
commit 15ade1232e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,16 +2,11 @@
import voluptuous as vol
from homeassistant.components.geo_location import DOMAIN
from homeassistant.const import (
CONF_EVENT,
CONF_PLATFORM,
CONF_SOURCE,
CONF_ZONE,
EVENT_STATE_CHANGED,
)
from homeassistant.const import CONF_EVENT, CONF_PLATFORM, CONF_SOURCE, CONF_ZONE
from homeassistant.core import callback
from homeassistant.helpers import condition, config_validation as cv
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
@ -45,9 +40,6 @@ async def async_attach_trigger(hass, config, action, automation_info):
@callback
def state_change_listener(event):
"""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.
from_state = event.data.get("old_state")
to_state = event.data.get("new_state")
@ -83,4 +75,6 @@ async def async_attach_trigger(hass, config, action, automation_info):
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