Update integrations to call async_remove_device (part 1) (#177962)

This commit is contained in:
Erik Montnemery
2026-08-04 14:33:44 +02:00
committed by Bram Kragten
parent 7eaae601bd
commit 57d44f891f
14 changed files with 18 additions and 60 deletions
@@ -240,10 +240,7 @@ class AmazonDevicesCoordinator(DataUpdateCoordinator[dict[str, AmazonDevice]]):
(DOMAIN, serial_num), self.config_entry.entry_id
)
if device:
device_registry.async_update_device(
device_id=device.id,
remove_config_entry_id=self.config_entry.entry_id,
)
device_registry.async_remove_device(device.id)
async def _async_remove_routine_stale(
self,
@@ -131,10 +131,7 @@ class AqvifyCoordinator(DataUpdateCoordinator[AqvifyCoordinatorData]):
self.config_entry.entry_id,
)
if device:
device_registry.async_update_device(
device_id=device.id,
remove_config_entry_id=self.config_entry.entry_id,
)
device_registry.async_remove_device(device.id)
self.previous_devices = current_devices
device_data = {}
+1 -1
View File
@@ -21,7 +21,7 @@ async def async_remove_devices(
(DOMAIN, entity.device_id), entry_id
)
if device is not None:
dev_registry.async_update_device(device.id, remove_config_entry_id=entry_id)
dev_registry.async_remove_device(device.id)
class SHCBaseEntity(Entity):
@@ -153,10 +153,7 @@ class ComelitBaseCoordinator(DataUpdateCoordinator[T]):
(DOMAIN, identifier), self.config_entry.entry_id
)
if device:
device_registry.async_update_device(
device_id=device.id,
remove_config_entry_id=self.config_entry.entry_id,
)
device_registry.async_remove_device(device.id)
class ComelitSerialBridge(ComelitBaseCoordinator[T]):
+5 -12
View File
@@ -68,13 +68,13 @@ async def cleanup_stale_entity(
identifiers.append(f"{config_entry.entry_id}-{device.type}-{device.index}")
if len(identifiers) > 0:
_async_remove_state_config_entry_from_devices(hass, identifiers, config_entry)
_async_remove_stale_devices(hass, identifiers, config_entry)
def _async_remove_state_config_entry_from_devices(
def _async_remove_stale_devices(
hass: HomeAssistant, identifiers: list[str], config_entry: ConfigEntry
) -> None:
"""Remove config entry from device."""
"""Remove stale devices."""
device_registry = dr.async_get(hass)
for identifier in identifiers:
@@ -82,15 +82,8 @@ def _async_remove_state_config_entry_from_devices(
(DOMAIN, identifier), config_entry.entry_id
)
if device:
LOGGER.info(
"Removing config entry %s from device %s",
config_entry.title,
device.name,
)
device_registry.async_update_device(
device_id=device.id,
remove_config_entry_id=config_entry.entry_id,
)
LOGGER.info("Removing device %s", device.name)
device_registry.async_remove_device(device.id)
def bridge_api_call[_T: ComelitBridgeBaseEntity, **_P](
+1 -4
View File
@@ -262,10 +262,7 @@ async def async_setup_entry(
(DOMAIN, f"{mac}_{node_id}"), entry.entry_id
)
if device:
device_reg.async_update_device(
device.id,
remove_config_entry_id=entry.entry_id,
)
device_reg.async_remove_device(device.id)
known_nodes.difference_update(stale_node_ids)
known_box_sensors.difference_update(
{
@@ -88,10 +88,7 @@ class FreshrDevicesCoordinator(DataUpdateCoordinator[dict[str, DeviceSummary]]):
if device := device_registry.async_get_device_by_identifier(
(DOMAIN, device_id), self.config_entry.entry_id
):
device_registry.async_update_device(
device.id,
remove_config_entry_id=self.config_entry.entry_id,
)
device_registry.async_remove_device(device.id)
return current
+1 -4
View File
@@ -101,10 +101,7 @@ class FytaCoordinator(DataUpdateCoordinator[dict[int, Plant]]):
(DOMAIN, f"{self.config_entry.entry_id}-{plant_id}"),
self.config_entry.entry_id,
):
device_registry.async_update_device(
device_id=device.id,
remove_config_entry_id=self.config_entry.entry_id,
)
device_registry.async_remove_device(device.id)
_LOGGER.debug("Device removed from device registry: %s", device.id)
# add new devices
@@ -368,10 +368,7 @@ class HomeConnectApplianceCoordinator(DataUpdateCoordinator[HomeConnectAppliance
(DOMAIN, self.data.info.ha_id), self._config_entry.entry_id
)
if device:
self.device_registry.async_update_device(
device_id=device.id,
remove_config_entry_id=self._config_entry.entry_id,
)
self.device_registry.async_remove_device(device.id)
for (
listener,
context,
+1 -4
View File
@@ -117,10 +117,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: HomeeConfigEntry) -> boo
)
if device:
_LOGGER.info("Removing device %s", device.name)
device_registry.async_update_device(
device_id=device.id,
remove_config_entry_id=entry.entry_id,
)
device_registry.async_remove_device(device.id)
homee.add_nodes_listener(_remove_node_callback)
+1 -3
View File
@@ -25,9 +25,7 @@ async def remove_devices(bridge, api_ids, current):
(DOMAIN, entity.device_id), bridge.config_entry.entry_id
)
if device is not None:
dev_registry.async_update_device(
device.id, remove_config_entry_id=bridge.config_entry.entry_id
)
dev_registry.async_remove_device(device.id)
for item_id in removed_items:
del current[item_id]
@@ -234,10 +234,7 @@ class AutomowerDataUpdateCoordinator(DataUpdateCoordinator[MowerDictionary]):
(DOMAIN, mower_id), self.config_entry.entry_id
)
if dev is not None:
device_registry.async_update_device(
device_id=dev.id,
remove_config_entry_id=self.config_entry.entry_id,
)
device_registry.async_remove_device(dev.id)
new_devices = current_devices - registered_devices
if new_devices:
+1 -4
View File
@@ -152,10 +152,7 @@ class ImouDataUpdateCoordinator(DataUpdateCoordinator[None]):
if device := device_registry.async_get_device_by_identifier(
(DOMAIN, device_key), self.config_entry.entry_id
):
device_registry.async_update_device(
device_id=device.id,
remove_config_entry_id=self.config_entry.entry_id,
)
device_registry.async_remove_device(device.id)
if new_keys := current_keys - known_keys:
_LOGGER.debug("New Imou device(s) found: %s", ", ".join(new_keys))
@@ -136,9 +136,6 @@ class LibreHardwareMonitorCoordinator(DataUpdateCoordinator[LibreHardwareMonitor
_LOGGER.debug(
"Removing device: %s", self._previous_devices[device_id]
)
device_registry.async_update_device(
device_id=device.id,
remove_config_entry_id=self._entry_id,
)
device_registry.async_remove_device(device.id)
self._previous_devices = detected_devices