Make sure all discovery flows are using the helper (#76641)
parent
a86397cc10
commit
eeb9a9f058
|
@ -249,12 +249,11 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
)
|
||||
)
|
||||
elif await _async_has_bluetooth_adapter():
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_INTEGRATION_DISCOVERY},
|
||||
data={},
|
||||
)
|
||||
discovery_flow.async_create_flow(
|
||||
hass,
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_INTEGRATION_DISCOVERY},
|
||||
data={},
|
||||
)
|
||||
return True
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ from homeassistant import config_entries
|
|||
from homeassistant.components import zeroconf
|
||||
from homeassistant.const import EVENT_HOMEASSISTANT_STARTED
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import discovery_flow
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.discovery import async_discover, async_load_platform
|
||||
from homeassistant.helpers.event import async_track_point_in_utc_time
|
||||
|
@ -173,7 +174,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
already_discovered.add(discovery_hash)
|
||||
|
||||
if service in CONFIG_ENTRY_HANDLERS:
|
||||
await hass.config_entries.flow.async_init(
|
||||
discovery_flow.async_create_flow(
|
||||
hass,
|
||||
CONFIG_ENTRY_HANDLERS[service],
|
||||
context={"source": config_entries.SOURCE_DISCOVERY},
|
||||
data=info,
|
||||
|
|
|
@ -10,7 +10,7 @@ from elkm1_lib.discovery import AIOELKDiscovery, ElkSystem
|
|||
from homeassistant import config_entries
|
||||
from homeassistant.components import network
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers import device_registry as dr, discovery_flow
|
||||
|
||||
from .const import DISCOVER_SCAN_TIMEOUT, DOMAIN
|
||||
|
||||
|
@ -87,10 +87,9 @@ def async_trigger_discovery(
|
|||
) -> None:
|
||||
"""Trigger config flows for discovered devices."""
|
||||
for device in discovered_devices:
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_INTEGRATION_DISCOVERY},
|
||||
data=asdict(device),
|
||||
)
|
||||
discovery_flow.async_create_flow(
|
||||
hass,
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_INTEGRATION_DISCOVERY},
|
||||
data=asdict(device),
|
||||
)
|
||||
|
|
|
@ -17,7 +17,11 @@ from homeassistant.config_entries import (
|
|||
)
|
||||
from homeassistant.const import CONF_IP_ADDRESS, CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||
from homeassistant.helpers import (
|
||||
config_validation as cv,
|
||||
discovery_flow,
|
||||
entity_platform,
|
||||
)
|
||||
|
||||
from .const import (
|
||||
ATTR_DIRECTION,
|
||||
|
@ -93,15 +97,14 @@ async def async_setup_entry(
|
|||
|
||||
else:
|
||||
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_INTEGRATION_DISCOVERY},
|
||||
data={
|
||||
ATTR_SERIAL: camera,
|
||||
CONF_IP_ADDRESS: value["local_ip"],
|
||||
},
|
||||
)
|
||||
discovery_flow.async_create_flow(
|
||||
hass,
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_INTEGRATION_DISCOVERY},
|
||||
data={
|
||||
ATTR_SERIAL: camera,
|
||||
CONF_IP_ADDRESS: value["local_ip"],
|
||||
},
|
||||
)
|
||||
|
||||
_LOGGER.warning(
|
||||
|
|
|
@ -27,7 +27,7 @@ from homeassistant.components import network
|
|||
from homeassistant.config_entries import ConfigEntry, ConfigEntryState
|
||||
from homeassistant.const import CONF_HOST, CONF_MODEL, CONF_NAME
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers import device_registry as dr, discovery_flow
|
||||
from homeassistant.util.network import is_ip_address
|
||||
|
||||
from .const import (
|
||||
|
@ -221,10 +221,9 @@ def async_trigger_discovery(
|
|||
) -> None:
|
||||
"""Trigger config flows for discovered devices."""
|
||||
for device in discovered_devices:
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_INTEGRATION_DISCOVERY},
|
||||
data={**device},
|
||||
)
|
||||
discovery_flow.async_create_flow(
|
||||
hass,
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_INTEGRATION_DISCOVERY},
|
||||
data={**device},
|
||||
)
|
||||
|
|
|
@ -14,6 +14,7 @@ from homeassistant.components.http import HomeAssistantView
|
|||
from homeassistant.const import ATTR_NAME, ATTR_SERVICE, EVENT_HOMEASSISTANT_START
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.data_entry_flow import BaseServiceInfo
|
||||
from homeassistant.helpers import discovery_flow
|
||||
|
||||
from .const import ATTR_ADDON, ATTR_CONFIG, ATTR_DISCOVERY, ATTR_UUID
|
||||
from .handler import HassioAPIError
|
||||
|
@ -99,7 +100,8 @@ class HassIODiscovery(HomeAssistantView):
|
|||
config_data[ATTR_ADDON] = addon_info[ATTR_NAME]
|
||||
|
||||
# Use config flow
|
||||
await self.hass.config_entries.flow.async_init(
|
||||
discovery_flow.async_create_flow(
|
||||
self.hass,
|
||||
service,
|
||||
context={"source": config_entries.SOURCE_HASSIO},
|
||||
data=HassioServiceInfo(config=config_data),
|
||||
|
|
|
@ -10,6 +10,7 @@ from homeassistant import config_entries
|
|||
from homeassistant.components import network
|
||||
from homeassistant.const import CONF_HOST
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import discovery_flow
|
||||
|
||||
from .const import CONF_SERIAL, DOMAIN
|
||||
|
||||
|
@ -38,12 +39,11 @@ async def async_discover_devices(hass: HomeAssistant) -> Iterable[Light]:
|
|||
@callback
|
||||
def async_init_discovery_flow(hass: HomeAssistant, host: str, serial: str) -> None:
|
||||
"""Start discovery of devices."""
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_INTEGRATION_DISCOVERY},
|
||||
data={CONF_HOST: host, CONF_SERIAL: serial},
|
||||
)
|
||||
discovery_flow.async_create_flow(
|
||||
hass,
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_INTEGRATION_DISCOVERY},
|
||||
data={CONF_HOST: host, CONF_SERIAL: serial},
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -22,7 +22,12 @@ from homeassistant.const import (
|
|||
)
|
||||
from homeassistant.core import HassJob, HomeAssistant, ServiceCall, callback
|
||||
from homeassistant.exceptions import TemplateError, Unauthorized
|
||||
from homeassistant.helpers import config_validation as cv, event, template
|
||||
from homeassistant.helpers import (
|
||||
config_validation as cv,
|
||||
discovery_flow,
|
||||
event,
|
||||
template,
|
||||
)
|
||||
from homeassistant.helpers.device_registry import DeviceEntry
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.reload import (
|
||||
|
@ -178,12 +183,11 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
# Create an import flow if the user has yaml configured entities etc.
|
||||
# but no broker configuration. Note: The intention is not for this to
|
||||
# import broker configuration from YAML because that has been deprecated.
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_INTEGRATION_DISCOVERY},
|
||||
data={},
|
||||
)
|
||||
discovery_flow.async_create_flow(
|
||||
hass,
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_INTEGRATION_DISCOVERY},
|
||||
data={},
|
||||
)
|
||||
hass.data[DATA_MQTT_RELOAD_NEEDED] = True
|
||||
elif mqtt_entry_status is False:
|
||||
|
|
|
@ -29,6 +29,7 @@ from homeassistant.const import (
|
|||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
from homeassistant.helpers import discovery_flow
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
|
@ -76,7 +77,8 @@ async def async_discover(hass):
|
|||
gdm = GDM()
|
||||
await hass.async_add_executor_job(gdm.scan)
|
||||
for server_data in gdm.entries:
|
||||
await hass.config_entries.flow.async_init(
|
||||
discovery_flow.async_create_flow(
|
||||
hass,
|
||||
DOMAIN,
|
||||
context={CONF_SOURCE: config_entries.SOURCE_INTEGRATION_DISCOVERY},
|
||||
data=server_data,
|
||||
|
|
|
@ -8,6 +8,7 @@ from aiosenseme import SensemeDevice, SensemeDiscovery
|
|||
from homeassistant import config_entries
|
||||
from homeassistant.const import CONF_ID
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import discovery_flow
|
||||
|
||||
from .const import DISCOVERY, DOMAIN
|
||||
|
||||
|
@ -55,10 +56,9 @@ def async_trigger_discovery(
|
|||
"""Trigger config flows for discovered devices."""
|
||||
for device in discovered_devices:
|
||||
if device.uuid:
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_INTEGRATION_DISCOVERY},
|
||||
data={CONF_ID: device.uuid},
|
||||
)
|
||||
discovery_flow.async_create_flow(
|
||||
hass,
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_INTEGRATION_DISCOVERY},
|
||||
data={CONF_ID: device.uuid},
|
||||
)
|
||||
|
|
|
@ -39,7 +39,11 @@ from homeassistant.const import (
|
|||
STATE_PLAYING,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||
from homeassistant.helpers import (
|
||||
config_validation as cv,
|
||||
discovery_flow,
|
||||
entity_platform,
|
||||
)
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.device_registry import format_mac
|
||||
from homeassistant.helpers.dispatcher import (
|
||||
|
@ -99,16 +103,15 @@ async def start_server_discovery(hass):
|
|||
"""Start a server discovery task."""
|
||||
|
||||
def _discovered_server(server):
|
||||
asyncio.create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_INTEGRATION_DISCOVERY},
|
||||
data={
|
||||
CONF_HOST: server.host,
|
||||
CONF_PORT: int(server.port),
|
||||
"uuid": server.uuid,
|
||||
},
|
||||
)
|
||||
discovery_flow.async_create_flow(
|
||||
hass,
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_INTEGRATION_DISCOVERY},
|
||||
data={
|
||||
CONF_HOST: server.host,
|
||||
CONF_PORT: int(server.port),
|
||||
"uuid": server.uuid,
|
||||
},
|
||||
)
|
||||
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
|
|
|
@ -11,7 +11,7 @@ from homeassistant import config_entries
|
|||
from homeassistant.components import network
|
||||
from homeassistant.const import CONF_MODEL, CONF_NAME
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers import device_registry as dr, discovery_flow
|
||||
from homeassistant.util.network import is_ip_address
|
||||
|
||||
from .const import DISCOVER_SCAN_TIMEOUT, DISCOVERY, DOMAIN
|
||||
|
@ -122,15 +122,14 @@ def async_trigger_discovery(
|
|||
) -> None:
|
||||
"""Trigger config flows for discovered devices."""
|
||||
for device in discovered_devices:
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_INTEGRATION_DISCOVERY},
|
||||
data={
|
||||
"ipaddress": device.ipaddress,
|
||||
"name": device.name,
|
||||
"mac": device.mac,
|
||||
"hostname": device.hostname,
|
||||
},
|
||||
)
|
||||
discovery_flow.async_create_flow(
|
||||
hass,
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_INTEGRATION_DISCOVERY},
|
||||
data={
|
||||
"ipaddress": device.ipaddress,
|
||||
"name": device.name,
|
||||
"mac": device.mac,
|
||||
"hostname": device.hostname,
|
||||
},
|
||||
)
|
||||
|
|
|
@ -19,7 +19,7 @@ from homeassistant.const import (
|
|||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers import device_registry as dr, discovery_flow
|
||||
from homeassistant.helpers.event import async_track_time_interval
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
|
@ -36,16 +36,15 @@ def async_trigger_discovery(
|
|||
) -> None:
|
||||
"""Trigger config flows for discovered devices."""
|
||||
for formatted_mac, device in discovered_devices.items():
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_INTEGRATION_DISCOVERY},
|
||||
data={
|
||||
CONF_NAME: device.alias,
|
||||
CONF_HOST: device.host,
|
||||
CONF_MAC: formatted_mac,
|
||||
},
|
||||
)
|
||||
discovery_flow.async_create_flow(
|
||||
hass,
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_INTEGRATION_DISCOVERY},
|
||||
data={
|
||||
CONF_NAME: device.alias,
|
||||
CONF_HOST: device.host,
|
||||
CONF_MAC: formatted_mac,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ from unifi_discovery import AIOUnifiScanner, UnifiDevice, UnifiService
|
|||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import discovery_flow
|
||||
from homeassistant.helpers.event import async_track_time_interval
|
||||
|
||||
from .const import DOMAIN
|
||||
|
@ -54,10 +55,9 @@ def async_trigger_discovery(
|
|||
"""Trigger config flows for discovered devices."""
|
||||
for device in discovered_devices:
|
||||
if device.services[UnifiService.Protect] and device.hw_addr:
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_INTEGRATION_DISCOVERY},
|
||||
data=asdict(device),
|
||||
)
|
||||
discovery_flow.async_create_flow(
|
||||
hass,
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_INTEGRATION_DISCOVERY},
|
||||
data=asdict(device),
|
||||
)
|
||||
|
|
|
@ -10,6 +10,7 @@ from pywizlight.discovery import DiscoveredBulb, find_wizlights
|
|||
from homeassistant import config_entries
|
||||
from homeassistant.components import network
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import discovery_flow
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
|
@ -46,10 +47,9 @@ def async_trigger_discovery(
|
|||
) -> None:
|
||||
"""Trigger config flows for discovered devices."""
|
||||
for device in discovered_devices:
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_INTEGRATION_DISCOVERY},
|
||||
data=asdict(device),
|
||||
)
|
||||
discovery_flow.async_create_flow(
|
||||
hass,
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_INTEGRATION_DISCOVERY},
|
||||
data=asdict(device),
|
||||
)
|
||||
|
|
|
@ -12,6 +12,7 @@ from homeassistant.config_entries import SOURCE_INTEGRATION_DISCOVERY, ConfigEnt
|
|||
from homeassistant.const import CONF_ADDRESS, Platform
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers import discovery_flow
|
||||
|
||||
from .const import CONF_KEY, CONF_LOCAL_NAME, CONF_SLOT, DEVICE_TIMEOUT, DOMAIN
|
||||
from .models import YaleXSBLEData
|
||||
|
@ -33,12 +34,11 @@ class YaleXSBLEDiscovery(TypedDict):
|
|||
@callback
|
||||
def async_discovery(hass: HomeAssistant, discovery: YaleXSBLEDiscovery) -> None:
|
||||
"""Update keys for the yalexs-ble integration if available."""
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
"yalexs_ble",
|
||||
context={"source": SOURCE_INTEGRATION_DISCOVERY},
|
||||
data=discovery,
|
||||
)
|
||||
discovery_flow.async_create_flow(
|
||||
hass,
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_INTEGRATION_DISCOVERY},
|
||||
data=discovery,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ from async_upnp_client.utils import CaseInsensitiveDict
|
|||
from homeassistant import config_entries
|
||||
from homeassistant.components import network, ssdp
|
||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
|
||||
from homeassistant.helpers import discovery_flow
|
||||
from homeassistant.helpers.event import async_call_later, async_track_time_interval
|
||||
|
||||
from .const import (
|
||||
|
@ -161,17 +162,16 @@ class YeelightScanner:
|
|||
def _async_discovered_by_ssdp(self, response: CaseInsensitiveDict) -> None:
|
||||
@callback
|
||||
def _async_start_flow(*_) -> None:
|
||||
asyncio.create_task(
|
||||
self._hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_SSDP},
|
||||
data=ssdp.SsdpServiceInfo(
|
||||
ssdp_usn="",
|
||||
ssdp_st=SSDP_ST,
|
||||
ssdp_headers=response,
|
||||
upnp={},
|
||||
),
|
||||
)
|
||||
discovery_flow.async_create_flow(
|
||||
self._hass,
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_SSDP},
|
||||
data=ssdp.SsdpServiceInfo(
|
||||
ssdp_usn="",
|
||||
ssdp_st=SSDP_ST,
|
||||
ssdp_headers=response,
|
||||
upnp={},
|
||||
),
|
||||
)
|
||||
|
||||
# Delay starting the flow in case the discovery is the result
|
||||
|
|
|
@ -4,7 +4,7 @@ from unittest.mock import Mock, patch
|
|||
|
||||
from homeassistant.components.hassio import HassioServiceInfo
|
||||
from homeassistant.components.hassio.handler import HassioAPIError
|
||||
from homeassistant.const import EVENT_HOMEASSISTANT_START
|
||||
from homeassistant.const import EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STARTED
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
|
||||
|
@ -45,7 +45,8 @@ async def test_hassio_discovery_startup(hass, aioclient_mock, hassio_client):
|
|||
) as mock_mqtt:
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
|
||||
await hass.async_block_till_done()
|
||||
assert aioclient_mock.call_count == 2
|
||||
assert mock_mqtt.called
|
||||
mock_mqtt.assert_called_with(
|
||||
|
@ -159,6 +160,8 @@ async def test_hassio_discovery_webhook(hass, aioclient_mock, hassio_client):
|
|||
json={"addon": "mosquitto", "service": "mqtt", "uuid": "testuuid"},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert resp.status == HTTPStatus.OK
|
||||
assert aioclient_mock.call_count == 2
|
||||
|
|
|
@ -703,6 +703,7 @@ async def test_integration_discovery(hass):
|
|||
|
||||
with patch("homeassistant.components.plex.config_flow.GDM", return_value=mock_gdm):
|
||||
await config_flow.async_discover(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
flows = hass.config_entries.flow.async_progress()
|
||||
|
||||
|
|
Loading…
Reference in New Issue