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

Use eager task creation to add entities to entity platform (#111553)

This commit is contained in:
J. Nick Koston
2024-02-27 09:54:51 -10:00
committed by GitHub
parent 8da2c53742
commit a6f4f6eae8
3 changed files with 10 additions and 4 deletions

View File

@@ -476,6 +476,7 @@ class EntityPlatform:
task = self.hass.async_create_task(
self.async_add_entities(new_entities, update_before_add=update_before_add),
f"EntityPlatform async_add_entities {self.domain}.{self.platform_name}",
eager_start=True,
)
if not self._setup_complete:
@@ -491,6 +492,7 @@ class EntityPlatform:
self.hass,
self.async_add_entities(new_entities, update_before_add=update_before_add),
f"EntityPlatform async_add_entities_for_entry {self.domain}.{self.platform_name}",
eager_start=True,
)
if not self._setup_complete:
@@ -526,9 +528,10 @@ class EntityPlatform:
event loop and will finish faster if we run them concurrently.
"""
results: list[BaseException | None] | None = None
tasks = [create_eager_task(coro) for coro in coros]
try:
async with self.hass.timeout.async_timeout(timeout, self.domain):
results = await asyncio.gather(*coros, return_exceptions=True)
results = await asyncio.gather(*tasks, return_exceptions=True)
except TimeoutError:
self.logger.warning(
"Timed out adding entities for domain %s with platform %s after %ds",