From 3e0e1716132d7e767427c5c225f25f54130c06bc Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Tue, 25 Aug 2026 10:30:02 +0200 Subject: [PATCH] Use get_device_and_config_entry_for_domain in simplisafe (#180110) --- .../components/simplisafe/services.py | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/homeassistant/components/simplisafe/services.py b/homeassistant/components/simplisafe/services.py index 57593063ab29..7dc5f5425145 100644 --- a/homeassistant/components/simplisafe/services.py +++ b/homeassistant/components/simplisafe/services.py @@ -135,11 +135,13 @@ def _async_get_system_for_service_call(call: ServiceCall) -> SystemType: if TYPE_CHECKING: assert alarm_control_panel_device_entry.via_device_id - if ( - base_station_device_entry := device_registry.async_get( - alarm_control_panel_device_entry.via_device_id + config_entry: SimpliSafeConfigEntry | None + base_station_device_entry, config_entry = ( + dr.async_get_device_and_config_entry_for_domain( + call.hass, alarm_control_panel_device_entry.via_device_id, domain=DOMAIN ) - ) is None: + ) + if base_station_device_entry is None: raise ServiceValidationError( translation_domain=DOMAIN, translation_key="no_base_station", @@ -153,21 +155,14 @@ def _async_get_system_for_service_call(call: ServiceCall) -> SystemType: ] system_id = int(system_id_str) - entry: SimpliSafeConfigEntry | None - for entry_id in base_station_device_entry.config_entries: - if ( - (entry := call.hass.config_entries.async_get_entry(entry_id)) is None - or entry.domain != DOMAIN - or entry.state is not ConfigEntryState.LOADED - ): - continue - return entry.runtime_data.systems[system_id] + if config_entry is None or config_entry.state is not ConfigEntryState.LOADED: + raise ServiceValidationError( + translation_domain=DOMAIN, + translation_key="no_system_for_device", + translation_placeholders={"device_id": device_id}, + ) - raise ServiceValidationError( - translation_domain=DOMAIN, - translation_key="no_system_for_device", - translation_placeholders={"device_id": device_id}, - ) + return config_entry.runtime_data.systems[system_id] @callback