mirror of
https://github.com/home-assistant/core.git
synced 2026-08-24 02:24:51 -05:00
Migrate integrations to call dr.async_entries_for_config_entry (#179550)
This commit is contained in:
@@ -132,8 +132,8 @@ class AmazonDevicesCoordinator(DataUpdateCoordinator[dict[str, AmazonDevice]]):
|
||||
device_registry = dr.async_get(hass)
|
||||
self.previous_devices: set[str] = {
|
||||
identifier
|
||||
for device in device_registry.devices.get_devices_for_config_entry_id(
|
||||
entry.entry_id
|
||||
for device in dr.async_entries_for_config_entry(
|
||||
device_registry, entry.entry_id
|
||||
)
|
||||
if device.entry_type != dr.DeviceEntryType.SERVICE
|
||||
for identifier_domain, identifier in device.identifiers
|
||||
|
||||
@@ -55,9 +55,7 @@ async def async_setup_entry(
|
||||
# As it has to be removed from the device on the app.
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
devices = device_registry.devices.get_devices_for_config_entry_id(
|
||||
config_entry.entry_id
|
||||
)
|
||||
devices = dr.async_entries_for_config_entry(device_registry, config_entry.entry_id)
|
||||
for device in devices:
|
||||
if device.model == BeoModel.BEOREMOTE_ONE and device.serial_number not in {
|
||||
remote.serial_number for remote in remotes
|
||||
|
||||
@@ -185,8 +185,8 @@ class BeoWebsocket(BeoBase):
|
||||
# Get remote devices connected to the device from Home Assistant
|
||||
device_serial_numbers = [
|
||||
device.serial_number
|
||||
for device in device_registry.devices.get_devices_for_config_entry_id(
|
||||
self.entry.entry_id
|
||||
for device in dr.async_entries_for_config_entry(
|
||||
device_registry, self.entry.entry_id
|
||||
)
|
||||
if device.serial_number is not None
|
||||
and device.model == BeoModel.BEOREMOTE_ONE
|
||||
|
||||
@@ -181,8 +181,8 @@ async def async_remove_orphaned_entries_service(hub: DeconzHub) -> None:
|
||||
entities_to_be_removed = []
|
||||
devices_to_be_removed = [
|
||||
entry.id
|
||||
for entry in device_registry.devices.get_devices_for_config_entry_id(
|
||||
hub.config_entry.entry_id
|
||||
for entry in dr.async_entries_for_config_entry(
|
||||
device_registry, hub.config_entry.entry_id
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
@@ -42,9 +42,7 @@ async def async_setup_entry(
|
||||
dev_reg = dr.async_get(hass)
|
||||
dev_ids = {
|
||||
identifier[1]
|
||||
for device in dev_reg.devices.get_devices_for_config_entry_id(
|
||||
config_entry.entry_id
|
||||
)
|
||||
for device in dr.async_entries_for_config_entry(dev_reg, config_entry.entry_id)
|
||||
for identifier in device.identifiers
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ async def async_setup_entry(
|
||||
dev_reg = dr.async_get(hass)
|
||||
dev_ids = {
|
||||
identifier[1]
|
||||
for device in dev_reg.devices.get_devices_for_config_entry_id(entry.entry_id)
|
||||
for device in dr.async_entries_for_config_entry(dev_reg, entry.entry_id)
|
||||
for identifier in device.identifiers
|
||||
}
|
||||
if not dev_ids:
|
||||
|
||||
@@ -1347,9 +1347,7 @@ class HassioAddOnDataUpdateCoordinator(DataUpdateCoordinator[HassioAddonData]):
|
||||
# Remove add-ons that are no longer installed from device registry
|
||||
supervisor_addon_devices = {
|
||||
list(device.identifiers)[0][1]
|
||||
for device in self.dev_reg.devices.get_devices_for_config_entry_id(
|
||||
self.entry_id
|
||||
)
|
||||
for device in dr.async_entries_for_config_entry(self.dev_reg, self.entry_id)
|
||||
if device.model == SupervisorEntityModel.ADDON
|
||||
}
|
||||
if stale_addons := supervisor_addon_devices - set(new_data.addons):
|
||||
@@ -1569,9 +1567,7 @@ class HassioMainDataUpdateCoordinator(DataUpdateCoordinator[HassioMainData]):
|
||||
# Remove mounts that no longer exists from device registry
|
||||
supervisor_mount_devices = {
|
||||
device.name
|
||||
for device in self.dev_reg.devices.get_devices_for_config_entry_id(
|
||||
self.entry_id
|
||||
)
|
||||
for device in dr.async_entries_for_config_entry(self.dev_reg, self.entry_id)
|
||||
if device.model == SupervisorEntityModel.MOUNT
|
||||
}
|
||||
if stale_mounts := supervisor_mount_devices - set(new_data.mounts):
|
||||
|
||||
@@ -32,9 +32,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: HeosConfigEntry) -> bool
|
||||
|
||||
# Migrate non-string device identifiers.
|
||||
device_registry = dr.async_get(hass)
|
||||
for device in device_registry.devices.get_devices_for_config_entry_id(
|
||||
entry.entry_id
|
||||
):
|
||||
for device in dr.async_entries_for_config_entry(device_registry, entry.entry_id):
|
||||
for ident in device.identifiers:
|
||||
if ident[0] != DOMAIN or isinstance(ident[1], str):
|
||||
continue
|
||||
|
||||
@@ -1008,7 +1008,7 @@ class HomeKit:
|
||||
"""Purge bridges that exist from failed pairing or manual resets."""
|
||||
devices_to_purge = [
|
||||
entry.id
|
||||
for entry in dev_reg.devices.get_devices_for_config_entry_id(self._entry_id)
|
||||
for entry in dr.async_entries_for_config_entry(dev_reg, self._entry_id)
|
||||
if (
|
||||
identifier not in entry.identifiers # type: ignore[comparison-overlap]
|
||||
or connection not in entry.connections # type: ignore[unreachable]
|
||||
|
||||
@@ -218,8 +218,8 @@ class AutomowerDataUpdateCoordinator(DataUpdateCoordinator[MowerDictionary]):
|
||||
|
||||
registered_devices: set[str] = {
|
||||
str(mower_id)
|
||||
for device in device_registry.devices.get_devices_for_config_entry_id(
|
||||
self.config_entry.entry_id
|
||||
for device in dr.async_entries_for_config_entry(
|
||||
device_registry, self.config_entry.entry_id
|
||||
)
|
||||
for domain, mower_id in device.identifiers
|
||||
if domain == DOMAIN
|
||||
|
||||
@@ -16,7 +16,7 @@ from homeassistant.components import bluetooth
|
||||
from homeassistant.components.bluetooth.match import BluetoothCallbackMatcher
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
|
||||
from homeassistant.helpers.device_registry import DeviceRegistry
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
from homeassistant.helpers.event import async_track_time_interval
|
||||
|
||||
@@ -112,7 +112,7 @@ class IBeaconCoordinator:
|
||||
"""Set up the iBeacon Coordinator."""
|
||||
|
||||
def __init__(
|
||||
self, hass: HomeAssistant, entry: ConfigEntry, registry: DeviceRegistry
|
||||
self, hass: HomeAssistant, entry: ConfigEntry, registry: dr.DeviceRegistry
|
||||
) -> None:
|
||||
"""Initialize the Coordinator."""
|
||||
self.hass = hass
|
||||
@@ -508,8 +508,8 @@ class IBeaconCoordinator:
|
||||
@callback
|
||||
def _async_restore_from_registry(self) -> None:
|
||||
"""Restore the state of the Coordinator from the device registry."""
|
||||
for device in self._dev_reg.devices.get_devices_for_config_entry_id(
|
||||
self._entry.entry_id
|
||||
for device in dr.async_entries_for_config_entry(
|
||||
self._dev_reg, self._entry.entry_id
|
||||
):
|
||||
if not (identifier := next(iter(device.identifiers), None)):
|
||||
continue
|
||||
|
||||
@@ -47,9 +47,7 @@ def async_cleanup_stale_devices(
|
||||
"""Cleanup stale heater devices and climates."""
|
||||
heater_serial_numbers = {heater.serial_no for heater in data.heaters}
|
||||
device_registry = dr.async_get(hass)
|
||||
device_entries = device_registry.devices.get_devices_for_config_entry_id(
|
||||
entry.entry_id
|
||||
)
|
||||
device_entries = dr.async_entries_for_config_entry(device_registry, entry.entry_id)
|
||||
stale_heater_serial_numbers: list[str] = [
|
||||
device_entry.serial_number
|
||||
for device_entry in device_entries
|
||||
|
||||
@@ -45,7 +45,7 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
|
||||
# supports core bluetooth discovery
|
||||
if config_entry.version == 1:
|
||||
dev_reg = dr.async_get(hass)
|
||||
devices = dev_reg.devices.get_devices_for_config_entry_id(config_entry.entry_id)
|
||||
devices = dr.async_entries_for_config_entry(dev_reg, config_entry.entry_id)
|
||||
|
||||
if len(devices) == 0:
|
||||
_LOGGER.error("Unable to migrate; No devices registered")
|
||||
|
||||
@@ -49,7 +49,7 @@ async def async_setup_entry(
|
||||
dev_reg = dr.async_get(hass)
|
||||
dev_ids = {
|
||||
identifier[1]
|
||||
for device in dev_reg.devices.get_devices_for_config_entry_id(entry.entry_id)
|
||||
for device in dr.async_entries_for_config_entry(dev_reg, entry.entry_id)
|
||||
for identifier in device.identifiers
|
||||
}
|
||||
|
||||
|
||||
@@ -350,9 +350,7 @@ class PS4Device(MediaPlayerEntity):
|
||||
self._attr_unique_id = entry.unique_id
|
||||
self.entity_id = entry.entity_id
|
||||
break
|
||||
for device in d_registry.devices.get_devices_for_config_entry_id(
|
||||
self._entry_id
|
||||
):
|
||||
for device in dr.async_entries_for_config_entry(d_registry, self._entry_id):
|
||||
# Rebuilt from the existing device entry, which already carries
|
||||
# the network MAC connection added by the live-status branch.
|
||||
self._attr_device_info = DeviceInfo(
|
||||
|
||||
@@ -110,8 +110,8 @@ def async_get_remove_sensor_options(
|
||||
device_registry = dr.async_get(hass)
|
||||
return [
|
||||
SelectOptionDict(value=device_entry.id, label=cast(str, device_entry.name))
|
||||
for device_entry in device_registry.devices.get_devices_for_config_entry_id(
|
||||
config_entry.entry_id
|
||||
for device_entry in dr.async_entries_for_config_entry(
|
||||
device_registry, config_entry.entry_id
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
@@ -917,7 +917,7 @@ def remove_stale_blu_trv_devices(
|
||||
return
|
||||
|
||||
dev_reg = dr.async_get(hass)
|
||||
devices = dev_reg.devices.get_devices_for_config_entry_id(entry.entry_id)
|
||||
devices = dr.async_entries_for_config_entry(dev_reg, entry.entry_id)
|
||||
config = rpc_device.config
|
||||
blutrv_keys = get_rpc_key_ids(config, BLU_TRV_IDENTIFIER)
|
||||
trv_addrs = [config[f"{BLU_TRV_IDENTIFIER}:{key}"]["addr"] for key in blutrv_keys]
|
||||
@@ -943,7 +943,7 @@ def remove_empty_sub_devices(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||
dev_reg = dr.async_get(hass)
|
||||
entity_reg = er.async_get(hass)
|
||||
|
||||
devices = dev_reg.devices.get_devices_for_config_entry_id(entry.entry_id)
|
||||
devices = dr.async_entries_for_config_entry(dev_reg, entry.entry_id)
|
||||
|
||||
for device in devices:
|
||||
if not device.via_device_id:
|
||||
|
||||
@@ -91,8 +91,8 @@ def _remove_old_devices(
|
||||
) -> None:
|
||||
device_registry = dr.async_get(hass)
|
||||
|
||||
for registered_device in device_registry.devices.get_devices_for_config_entry_id(
|
||||
entry.entry_id
|
||||
for registered_device in dr.async_entries_for_config_entry(
|
||||
device_registry, entry.entry_id
|
||||
):
|
||||
mac = next(
|
||||
(i[1] for i in registered_device.identifiers if i[0] == DOMAIN), None
|
||||
|
||||
@@ -95,7 +95,7 @@ async def async_setup_entry(
|
||||
dev_reg = dr.async_get(hass)
|
||||
dev_ids = {
|
||||
identifier[1]
|
||||
for device in dev_reg.devices.get_devices_for_config_entry_id(entry.entry_id)
|
||||
for device in dr.async_entries_for_config_entry(dev_reg, entry.entry_id)
|
||||
for identifier in device.identifiers
|
||||
}
|
||||
if not dev_ids:
|
||||
|
||||
Reference in New Issue
Block a user