From 16de2ee9b99057183bce149020f9007a88fd2a7f Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Wed, 9 Sep 2026 17:53:19 +0200 Subject: [PATCH] Adjust shelly to not access DeviceEntry.config_entries (#181765) --- .../components/shelly/coordinator.py | 46 +++++++++---------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/homeassistant/components/shelly/coordinator.py b/homeassistant/components/shelly/coordinator.py index fb9caa3685b8..818809b9d678 100644 --- a/homeassistant/components/shelly/coordinator.py +++ b/homeassistant/components/shelly/coordinator.py @@ -909,18 +909,17 @@ def get_block_coordinator_by_device_id( hass: HomeAssistant, device_id: str ) -> ShellyBlockCoordinator | None: """Get a Shelly block device coordinator for the given device id.""" - dev_reg = dr.async_get(hass) - if device := dev_reg.async_get(device_id): - for config_entry in device.config_entries: - entry = hass.config_entries.async_get_entry(config_entry) - if ( - entry - and entry.state is ConfigEntryState.LOADED - and hasattr(entry, "runtime_data") - and isinstance(entry.runtime_data, ShellyEntryData) - and (coordinator := entry.runtime_data.block) - ): - return coordinator + _device, entry = dr.async_get_device_and_config_entry_for_domain( + hass, device_id, domain=DOMAIN + ) + if ( + entry is not None + and entry.state is ConfigEntryState.LOADED + and hasattr(entry, "runtime_data") + and isinstance(entry.runtime_data, ShellyEntryData) + and (coordinator := entry.runtime_data.block) + ): + return coordinator return None @@ -929,18 +928,17 @@ def get_rpc_coordinator_by_device_id( hass: HomeAssistant, device_id: str ) -> ShellyRpcCoordinator | None: """Get a Shelly RPC device coordinator for the given device id.""" - dev_reg = dr.async_get(hass) - if device := dev_reg.async_get(device_id): - for config_entry in device.config_entries: - entry = hass.config_entries.async_get_entry(config_entry) - if ( - entry - and entry.state is ConfigEntryState.LOADED - and hasattr(entry, "runtime_data") - and isinstance(entry.runtime_data, ShellyEntryData) - and (coordinator := entry.runtime_data.rpc) - ): - return coordinator + _device, entry = dr.async_get_device_and_config_entry_for_domain( + hass, device_id, domain=DOMAIN + ) + if ( + entry is not None + and entry.state is ConfigEntryState.LOADED + and hasattr(entry, "runtime_data") + and isinstance(entry.runtime_data, ShellyEntryData) + and (coordinator := entry.runtime_data.rpc) + ): + return coordinator return None