mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Avoid linear search to clear labels and areas in the device registry (#115676)
This commit is contained in:
parent
9ca24ab2a2
commit
8cf14c9268
@ -1053,18 +1053,14 @@ class DeviceRegistry(BaseRegistry[dict[str, list[dict[str, Any]]]]):
|
|||||||
@callback
|
@callback
|
||||||
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 dev_id, device in self.devices.items():
|
for device in self.devices.get_devices_for_area_id(area_id):
|
||||||
if area_id == device.area_id:
|
self.async_update_device(device.id, area_id=None)
|
||||||
self.async_update_device(dev_id, area_id=None)
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
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_id, entry in self.devices.items():
|
for device in self.devices.get_devices_for_label(label_id):
|
||||||
if label_id in entry.labels:
|
self.async_update_device(device.id, labels=device.labels - {label_id})
|
||||||
labels = entry.labels.copy()
|
|
||||||
labels.remove(label_id)
|
|
||||||
self.async_update_device(device_id, labels=labels)
|
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
Loading…
x
Reference in New Issue
Block a user