From dd109839b9ddc8b33d2ef1c0039c51b7e1b67c5e Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Fri, 19 Aug 2022 01:39:48 -0600 Subject: [PATCH] Provide slight speedup to Guardian device lookup during service call (#77004) * Provide slight speedup to Guardian device lookup during service call * Messages --- homeassistant/components/guardian/__init__.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/guardian/__init__.py b/homeassistant/components/guardian/__init__.py index 909752b5b33..a30536f66c3 100644 --- a/homeassistant/components/guardian/__init__.py +++ b/homeassistant/components/guardian/__init__.py @@ -103,12 +103,16 @@ def async_get_entry_id_for_service_call(hass: HomeAssistant, call: ServiceCall) device_id = call.data[CONF_DEVICE_ID] device_registry = dr.async_get(hass) - if device_entry := device_registry.async_get(device_id): - for entry in hass.config_entries.async_entries(DOMAIN): - if entry.entry_id in device_entry.config_entries: - return entry.entry_id + if (device_entry := device_registry.async_get(device_id)) is None: + raise ValueError(f"Invalid Guardian device ID: {device_id}") - raise ValueError(f"No client for device ID: {device_id}") + for entry_id in device_entry.config_entries: + if (entry := hass.config_entries.async_get_entry(entry_id)) is None: + continue + if entry.domain == DOMAIN: + return entry_id + + raise ValueError(f"No config entry for device ID: {device_id}") @callback