Use discovery flow helper for hardware integrations (#111437)

* Use discovery flow helper for hardware integrations

The discovery flow helper defers loading discovered integrations until after startup
to improve startup reliability.

* Use discovery flow helper for hardware integrations

The discovery flow helper defers loading discovered integrations until after startup
to improve startup reliability. Since hardware was not listed in as a
discovery integration, the notification for new discoveries was missing.
This commit is contained in:
J. Nick Koston 2024-02-26 07:04:33 -10:00 committed by GitHub
parent f85a8c5041
commit 4624c859e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 15 additions and 9 deletions

View File

@ -7,9 +7,10 @@ from homeassistant.components.homeassistant_hardware.silabs_multiprotocol_addon
get_zigbee_socket, get_zigbee_socket,
multi_pan_addon_using_device, multi_pan_addon_using_device,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import SOURCE_HARDWARE, ConfigEntry
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import ConfigEntryNotReady, HomeAssistantError from homeassistant.exceptions import ConfigEntryNotReady, HomeAssistantError
from homeassistant.helpers import discovery_flow
from .const import DOMAIN from .const import DOMAIN
from .util import get_usb_service_info from .util import get_usb_service_info
@ -51,9 +52,10 @@ async def _async_usb_scan_done(hass: HomeAssistant, entry: ConfigEntry) -> None:
}, },
"radio_type": "ezsp", "radio_type": "ezsp",
} }
await hass.config_entries.flow.async_init( discovery_flow.async_create_flow(
hass,
"zha", "zha",
context={"source": "hardware"}, context={"source": SOURCE_HARDWARE},
data=hw_discovery_data, data=hw_discovery_data,
) )

View File

@ -7,9 +7,10 @@ from homeassistant.components.homeassistant_hardware.silabs_multiprotocol_addon
get_zigbee_socket, get_zigbee_socket,
multi_pan_addon_using_device, multi_pan_addon_using_device,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import SOURCE_HARDWARE, ConfigEntry
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady, HomeAssistantError from homeassistant.exceptions import ConfigEntryNotReady, HomeAssistantError
from homeassistant.helpers import discovery_flow
from .const import RADIO_DEVICE, ZHA_HW_DISCOVERY_DATA from .const import RADIO_DEVICE, ZHA_HW_DISCOVERY_DATA
@ -47,9 +48,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"radio_type": "ezsp", "radio_type": "ezsp",
} }
await hass.config_entries.flow.async_init( discovery_flow.async_create_flow(
hass,
"zha", "zha",
context={"source": "hardware"}, context={"source": SOURCE_HARDWARE},
data=hw_discovery_data, data=hw_discovery_data,
) )

View File

@ -78,6 +78,7 @@ _LOGGER = logging.getLogger(__name__)
SOURCE_BLUETOOTH = "bluetooth" SOURCE_BLUETOOTH = "bluetooth"
SOURCE_DHCP = "dhcp" SOURCE_DHCP = "dhcp"
SOURCE_DISCOVERY = "discovery" SOURCE_DISCOVERY = "discovery"
SOURCE_HARDWARE = "hardware"
SOURCE_HASSIO = "hassio" SOURCE_HASSIO = "hassio"
SOURCE_HOMEKIT = "homekit" SOURCE_HOMEKIT = "homekit"
SOURCE_IMPORT = "import" SOURCE_IMPORT = "import"
@ -159,6 +160,7 @@ DISCOVERY_SOURCES = {
SOURCE_BLUETOOTH, SOURCE_BLUETOOTH,
SOURCE_DHCP, SOURCE_DHCP,
SOURCE_DISCOVERY, SOURCE_DISCOVERY,
SOURCE_HARDWARE,
SOURCE_HOMEKIT, SOURCE_HOMEKIT,
SOURCE_IMPORT, SOURCE_IMPORT,
SOURCE_INTEGRATION_DISCOVERY, SOURCE_INTEGRATION_DISCOVERY,

View File

@ -976,7 +976,7 @@ async def test_hardware(onboarded, hass: HomeAssistant) -> None:
"homeassistant.components.onboarding.async_is_onboarded", return_value=onboarded "homeassistant.components.onboarding.async_is_onboarded", return_value=onboarded
): ):
result1 = await hass.config_entries.flow.async_init( result1 = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": "hardware"}, data=data DOMAIN, context={"source": config_entries.SOURCE_HARDWARE}, data=data
) )
if onboarded: if onboarded:
@ -1029,7 +1029,7 @@ async def test_hardware_already_setup(hass: HomeAssistant) -> None:
}, },
} }
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": "hardware"}, data=data DOMAIN, context={"source": config_entries.SOURCE_HARDWARE}, data=data
) )
assert result["type"] == FlowResultType.ABORT assert result["type"] == FlowResultType.ABORT
@ -1043,7 +1043,7 @@ async def test_hardware_invalid_data(hass: HomeAssistant, data) -> None:
"""Test onboarding flow -- invalid data.""" """Test onboarding flow -- invalid data."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": "hardware"}, data=data DOMAIN, context={"source": config_entries.SOURCE_HARDWARE}, data=data
) )
assert result["type"] == FlowResultType.ABORT assert result["type"] == FlowResultType.ABORT