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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user