Migrate system flows to use the discovery helper (#112291)

Ensures we are not creating new flows or loading
their platforms until the started event
once the import executor has clamed down
This commit is contained in:
J. Nick Koston 2024-03-05 05:01:31 -10:00 committed by GitHub
parent 7cb8a8bbc9
commit a277d0c4b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 14 deletions

View File

@ -11,7 +11,7 @@ from hass_nabucasa import Cloud
import voluptuous as vol import voluptuous as vol
from homeassistant.components import alexa, google_assistant from homeassistant.components import alexa, google_assistant
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import SOURCE_SYSTEM, ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
CONF_DESCRIPTION, CONF_DESCRIPTION,
CONF_MODE, CONF_MODE,
@ -304,7 +304,9 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
return return
loaded = True loaded = True
await hass.config_entries.flow.async_init(DOMAIN, context={"source": "system"}) await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_SYSTEM}
)
async def _on_connect() -> None: async def _on_connect() -> None:
"""Handle cloud connect.""" """Handle cloud connect."""

View File

@ -14,7 +14,7 @@ import voluptuous as vol
from homeassistant.auth.const import GROUP_ID_ADMIN from homeassistant.auth.const import GROUP_ID_ADMIN
from homeassistant.components import panel_custom from homeassistant.components import panel_custom
from homeassistant.components.homeassistant import async_set_stop_handler from homeassistant.components.homeassistant import async_set_stop_handler
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import SOURCE_SYSTEM, ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
ATTR_NAME, ATTR_NAME,
EVENT_CORE_CONFIG_UPDATE, EVENT_CORE_CONFIG_UPDATE,
@ -30,7 +30,11 @@ from homeassistant.core import (
callback, callback,
) )
from homeassistant.exceptions import HomeAssistantError from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import config_validation as cv, device_registry as dr from homeassistant.helpers import (
config_validation as cv,
device_registry as dr,
discovery_flow,
)
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.event import async_call_later from homeassistant.helpers.event import async_call_later
from homeassistant.helpers.storage import Store from homeassistant.helpers.storage import Store
@ -490,11 +494,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa:
return return
if (hw_integration := HARDWARE_INTEGRATIONS.get(board)) is None: if (hw_integration := HARDWARE_INTEGRATIONS.get(board)) is None:
return return
hass.async_create_task( discovery_flow.async_create_flow(
hass.config_entries.flow.async_init( hass, hw_integration, context={"source": SOURCE_SYSTEM}, data={}
hw_integration, context={"source": "system"}
),
eager_start=True,
) )
async_setup_hardware_integration_job = HassJob( async_setup_hardware_integration_job = HassJob(
@ -502,12 +503,9 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa:
) )
_async_setup_hardware_integration() _async_setup_hardware_integration()
discovery_flow.async_create_flow(
hass.async_create_task( hass, DOMAIN, context={"source": SOURCE_SYSTEM}, data={}
hass.config_entries.flow.async_init(DOMAIN, context={"source": "system"}),
eager_start=True,
) )
return True return True

View File

@ -87,6 +87,7 @@ SOURCE_IMPORT = "import"
SOURCE_INTEGRATION_DISCOVERY = "integration_discovery" SOURCE_INTEGRATION_DISCOVERY = "integration_discovery"
SOURCE_MQTT = "mqtt" SOURCE_MQTT = "mqtt"
SOURCE_SSDP = "ssdp" SOURCE_SSDP = "ssdp"
SOURCE_SYSTEM = "system"
SOURCE_USB = "usb" SOURCE_USB = "usb"
SOURCE_USER = "user" SOURCE_USER = "user"
SOURCE_ZEROCONF = "zeroconf" SOURCE_ZEROCONF = "zeroconf"