From b2f7fd12a2af7f348d5d9fd788a42aac6724a365 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 10 Jan 2024 13:03:09 -1000 Subject: [PATCH] Add comment to ConfigEntry.async_setup about race safety (#107756) --- homeassistant/config_entries.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/homeassistant/config_entries.py b/homeassistant/config_entries.py index 336261c3632..d8738e67a04 100644 --- a/homeassistant/config_entries.py +++ b/homeassistant/config_entries.py @@ -478,6 +478,12 @@ class ConfigEntry: if self.domain != integration.domain: return + # + # It is important that this function does not yield to the + # event loop by using `await` or `async with` or similar until + # after the state has been set. Otherwise we risk that any `call_soon`s + # created by an integration will be executed before the state is set. + # if result: self._async_set_state(hass, ConfigEntryState.LOADED, None) else: