From 15ade1232e587af9272b9c4adc3d4b20622a83b0 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 5 Oct 2020 07:25:41 -0500 Subject: [PATCH] Setup geo_location to only track the geo_location domain (#41254) The trigger was watching for all states --- homeassistant/components/geo_location/trigger.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/geo_location/trigger.py b/homeassistant/components/geo_location/trigger.py index dc8879b51e5..415f5f48de5 100644 --- a/homeassistant/components/geo_location/trigger.py +++ b/homeassistant/components/geo_location/trigger.py @@ -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