Call DeviceRegistry._async_update_device from device registry

This commit is contained in:
Erik
2025-08-28 09:36:01 +02:00
parent 61328129fc
commit 815b26dcac

View File

@@ -988,7 +988,7 @@ class DeviceRegistry(BaseRegistry[dict[str, list[dict[str, Any]]]]):
via_device_id=via_device_id, via_device_id=via_device_id,
) )
# This is safe because async_update_device will always return a device # This is safe because _async_update_device will always return a device
# in this use case. # in this use case.
assert device assert device
return device return device
@@ -1265,7 +1265,7 @@ class DeviceRegistry(BaseRegistry[dict[str, list[dict[str, Any]]]]):
# Change modified_at if we are changing something that we store # Change modified_at if we are changing something that we store
new_values["modified_at"] = utcnow() new_values["modified_at"] = utcnow()
self.hass.verify_event_loop_thread("device_registry.async_update_device") self.hass.verify_event_loop_thread("device_registry._async_update_device")
new = attr.evolve(old, **new_values) new = attr.evolve(old, **new_values)
self.devices[device_id] = new self.devices[device_id] = new
@@ -1437,7 +1437,7 @@ class DeviceRegistry(BaseRegistry[dict[str, list[dict[str, Any]]]]):
) )
for other_device in list(self.devices.values()): for other_device in list(self.devices.values()):
if other_device.via_device_id == device_id: if other_device.via_device_id == device_id:
self.async_update_device(other_device.id, via_device_id=None) self._async_update_device(other_device.id, via_device_id=None)
self.hass.bus.async_fire_internal( self.hass.bus.async_fire_internal(
EVENT_DEVICE_REGISTRY_UPDATED, EVENT_DEVICE_REGISTRY_UPDATED,
_EventDeviceRegistryUpdatedData_Remove( _EventDeviceRegistryUpdatedData_Remove(
@@ -1546,7 +1546,7 @@ class DeviceRegistry(BaseRegistry[dict[str, list[dict[str, Any]]]]):
"""Clear config entry from registry entries.""" """Clear config entry from registry entries."""
now_time = time.time() now_time = time.time()
for device in self.devices.get_devices_for_config_entry_id(config_entry_id): for device in self.devices.get_devices_for_config_entry_id(config_entry_id):
self.async_update_device(device.id, remove_config_entry_id=config_entry_id) self._async_update_device(device.id, remove_config_entry_id=config_entry_id)
for deleted_device in list(self.deleted_devices.values()): for deleted_device in list(self.deleted_devices.values()):
config_entries = deleted_device.config_entries config_entries = deleted_device.config_entries
if config_entry_id not in config_entries: if config_entry_id not in config_entries:
@@ -1582,7 +1582,7 @@ class DeviceRegistry(BaseRegistry[dict[str, list[dict[str, Any]]]]):
now_time = time.time() now_time = time.time()
now_time = time.time() now_time = time.time()
for device in self.devices.get_devices_for_config_entry_id(config_entry_id): for device in self.devices.get_devices_for_config_entry_id(config_entry_id):
self.async_update_device( self._async_update_device(
device.id, device.id,
remove_config_entry_id=config_entry_id, remove_config_entry_id=config_entry_id,
remove_config_subentry_id=config_subentry_id, remove_config_subentry_id=config_subentry_id,
@@ -1643,7 +1643,7 @@ class DeviceRegistry(BaseRegistry[dict[str, list[dict[str, Any]]]]):
def async_clear_area_id(self, area_id: str) -> None: def async_clear_area_id(self, area_id: str) -> None:
"""Clear area id from registry entries.""" """Clear area id from registry entries."""
for device in self.devices.get_devices_for_area_id(area_id): for device in self.devices.get_devices_for_area_id(area_id):
self.async_update_device(device.id, area_id=None) self._async_update_device(device.id, area_id=None)
for deleted_device in list(self.deleted_devices.values()): for deleted_device in list(self.deleted_devices.values()):
if deleted_device.area_id != area_id: if deleted_device.area_id != area_id:
continue continue
@@ -1656,7 +1656,7 @@ class DeviceRegistry(BaseRegistry[dict[str, list[dict[str, Any]]]]):
def async_clear_label_id(self, label_id: str) -> None: def async_clear_label_id(self, label_id: str) -> None:
"""Clear label from registry entries.""" """Clear label from registry entries."""
for device in self.devices.get_devices_for_label(label_id): for device in self.devices.get_devices_for_label(label_id):
self.async_update_device(device.id, labels=device.labels - {label_id}) self._async_update_device(device.id, labels=device.labels - {label_id})
for deleted_device in list(self.deleted_devices.values()): for deleted_device in list(self.deleted_devices.values()):
if label_id not in deleted_device.labels: if label_id not in deleted_device.labels:
continue continue
@@ -1720,7 +1720,7 @@ def async_config_entry_disabled_by_changed(
for device in devices: for device in devices:
if device.disabled_by is not DeviceEntryDisabler.CONFIG_ENTRY: if device.disabled_by is not DeviceEntryDisabler.CONFIG_ENTRY:
continue continue
registry.async_update_device(device.id, disabled_by=None) registry._async_update_device(device.id, disabled_by=None) # noqa: SLF001
return return
enabled_config_entries = { enabled_config_entries = {
@@ -1737,7 +1737,7 @@ def async_config_entry_disabled_by_changed(
enabled_config_entries enabled_config_entries
): ):
continue continue
registry.async_update_device( registry._async_update_device( # noqa: SLF001
device.id, disabled_by=DeviceEntryDisabler.CONFIG_ENTRY device.id, disabled_by=DeviceEntryDisabler.CONFIG_ENTRY
) )
@@ -1775,7 +1775,7 @@ def async_cleanup(
for device in list(dev_reg.devices.values()): for device in list(dev_reg.devices.values()):
for config_entry_id in device.config_entries: for config_entry_id in device.config_entries:
if config_entry_id not in config_entry_ids: if config_entry_id not in config_entry_ids:
dev_reg.async_update_device( dev_reg._async_update_device( # noqa: SLF001
device.id, remove_config_entry_id=config_entry_id device.id, remove_config_entry_id=config_entry_id
) )