Adjust shelly to not access DeviceEntry.config_entries (#181765)

This commit is contained in:
Erik Montnemery
2026-09-09 17:53:19 +02:00
committed by GitHub
parent f23e2bd8b5
commit 16de2ee9b9
+22 -24
View File
@@ -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