mirror of
https://github.com/home-assistant/core.git
synced 2026-09-26 01:11:51 -04:00
Adjust shelly to not access DeviceEntry.config_entries (#181765)
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user