1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Avoid creating tasks to remove entities (#110967)

This commit is contained in:
J. Nick Koston
2024-02-20 21:32:36 -06:00
committed by GitHub
parent db77e73a76
commit 1a02330bd9
2 changed files with 21 additions and 10 deletions

View File

@@ -792,9 +792,17 @@ class EntityPlatform:
if not self.entities:
return
tasks = [entity.async_remove() for entity in self.entities.values()]
await asyncio.gather(*tasks)
# Removals are awaited in series since in most
# cases calling async_remove will not yield control
# to the event loop and we want to avoid scheduling
# one task per entity.
for entity in list(self.entities.values()):
try:
await entity.async_remove()
except Exception: # pylint: disable=broad-except
self.logger.exception(
"Error while removing entity %s", entity.entity_id
)
self.async_unsub_polling()
self._setup_complete = False