Fix race in MQTT platform setup (#72344)

Make sure MQTT platforms setup locks discovery
This commit is contained in:
Jan Bouwhuis 2022-05-23 09:03:30 +02:00 committed by GitHub
parent cf5e21a996
commit eb988f7792
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -816,15 +816,19 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
hass.data[DATA_CONFIG_ENTRY_LOCK] = asyncio.Lock()
hass.data[CONFIG_ENTRY_IS_SETUP] = set()
async def async_forward_entry_setup():
"""Forward the config entry setup to the platforms."""
async with hass.data[DATA_CONFIG_ENTRY_LOCK]:
for component in PLATFORMS:
config_entries_key = f"{component}.mqtt"
if config_entries_key not in hass.data[CONFIG_ENTRY_IS_SETUP]:
hass.data[CONFIG_ENTRY_IS_SETUP].add(config_entries_key)
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, component)
await hass.config_entries.async_forward_entry_setup(
entry, component
)
hass.async_create_task(async_forward_entry_setup())
if conf.get(CONF_DISCOVERY):
await _async_setup_discovery(hass, conf, entry)