Fix mqtt platform setup race (#112888)

This commit is contained in:
Jan Bouwhuis
2024-03-10 19:36:17 +01:00
committed by GitHub
parent eb81bf1d49
commit c608d1cb85
3 changed files with 19 additions and 12 deletions

View File

@@ -53,14 +53,12 @@ async def async_forward_entry_setup_and_setup_discovery(
mqtt_data = get_mqtt_data(hass)
platforms_loaded = mqtt_data.platforms_loaded
new_platforms: set[Platform | str] = platforms - platforms_loaded
platforms_loaded.update(new_platforms)
tasks: list[asyncio.Task] = []
if "device_automation" in new_platforms:
# Local import to avoid circular dependencies
# pylint: disable-next=import-outside-toplevel
from . import device_automation
new_platforms.remove("device_automation")
tasks.append(
create_eager_task(device_automation.async_setup_entry(hass, config_entry))
)
@@ -69,19 +67,19 @@ async def async_forward_entry_setup_and_setup_discovery(
# pylint: disable-next=import-outside-toplevel
from . import tag
new_platforms.remove("tag")
tasks.append(create_eager_task(tag.async_setup_entry(hass, config_entry)))
if new_platforms:
if new_entity_platforms := (new_platforms - {"tag", "device_automation"}):
tasks.append(
create_eager_task(
hass.config_entries.async_forward_entry_setups(
config_entry, new_platforms
config_entry, new_entity_platforms
)
)
)
if not tasks:
return
await asyncio.gather(*tasks)
platforms_loaded.update(new_platforms)
def mqtt_config_entry_enabled(hass: HomeAssistant) -> bool | None: