Avoid linear search to remove a label from the entity registry (#115674)

* Avoid linear search to remove a label from the entity registry

* simplify
This commit is contained in:
J. Nick Koston
2024-04-17 08:47:56 -05:00
committed by GitHub
parent 8cf14c9268
commit 45f025480e

View File

@@ -1329,11 +1329,8 @@ class EntityRegistry(BaseRegistry):
@callback
def async_clear_label_id(self, label_id: str) -> None:
"""Clear label from registry entries."""
for entity_id, entry in self.entities.items():
if label_id in entry.labels:
labels = entry.labels.copy()
labels.remove(label_id)
self.async_update_entity(entity_id, labels=labels)
for entry in self.entities.get_entries_for_label(label_id):
self.async_update_entity(entry.entity_id, labels=entry.labels - {label_id})
@callback
def async_clear_config_entry(self, config_entry_id: str) -> None: