From a6f4f6eae8e0dd5c1e5397c3d4d96aa9964522b5 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 27 Feb 2024 09:54:51 -1000 Subject: [PATCH] Use eager task creation to add entities to entity platform (#111553) --- homeassistant/helpers/entity_platform.py | 5 ++++- tests/components/honeywell/test_init.py | 7 +++++-- tests/components/netatmo/test_init.py | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/homeassistant/helpers/entity_platform.py b/homeassistant/helpers/entity_platform.py index 7a94581baab..3a441e75e84 100644 --- a/homeassistant/helpers/entity_platform.py +++ b/homeassistant/helpers/entity_platform.py @@ -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", diff --git a/tests/components/honeywell/test_init.py b/tests/components/honeywell/test_init.py index 98578217af6..8be7cfeb61a 100644 --- a/tests/components/honeywell/test_init.py +++ b/tests/components/honeywell/test_init.py @@ -195,15 +195,18 @@ async def test_remove_stale_device( (DOMAIN, 7654321) in device.identifiers for device in device_entries_other ) - assert await config_entry.async_unload(hass) + assert await hass.config_entries.async_unload(config_entry.entry_id) await hass.async_block_till_done() - assert config_entry.state == ConfigEntryState.NOT_LOADED + assert config_entry.state is ConfigEntryState.NOT_LOADED del location.devices_by_id[another_device.deviceid] await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() + await hass.async_block_till_done() + assert config_entry.state is ConfigEntryState.LOADED + assert ( hass.states.async_entity_ids_count() == 3 ) # 1 climate entities; 2 sensor entities diff --git a/tests/components/netatmo/test_init.py b/tests/components/netatmo/test_init.py index 3e0231579a8..2fd9867262d 100644 --- a/tests/components/netatmo/test_init.py +++ b/tests/components/netatmo/test_init.py @@ -121,7 +121,7 @@ async def test_setup_component_with_config( await hass.async_block_till_done() - assert fake_post_hits == 10 + assert fake_post_hits >= 8 mock_impl.assert_called_once() mock_webhook.assert_called_once()