Skip to content

Commit

Permalink
Use discovery flow helper for hardware integrations (home-assistant#1…
Browse files Browse the repository at this point in the history
…11437)

* 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.
  • Loading branch information
bdraco authored Feb 26, 2024
1 parent f85a8c5 commit 4624c85
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
get_zigbee_socket,
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.exceptions import ConfigEntryNotReady, HomeAssistantError
from homeassistant.helpers import discovery_flow

from .const import DOMAIN
from .util import get_usb_service_info
Expand Down Expand Up @@ -51,9 +52,10 @@ async def _async_usb_scan_done(hass: HomeAssistant, entry: ConfigEntry) -> None:
},
"radio_type": "ezsp",
}
await hass.config_entries.flow.async_init(
discovery_flow.async_create_flow(
hass,
"zha",
context={"source": "hardware"},
context={"source": SOURCE_HARDWARE},
data=hw_discovery_data,
)

Expand Down
8 changes: 5 additions & 3 deletions homeassistant/components/homeassistant_yellow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
get_zigbee_socket,
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.exceptions import ConfigEntryNotReady, HomeAssistantError
from homeassistant.helpers import discovery_flow

from .const import RADIO_DEVICE, ZHA_HW_DISCOVERY_DATA

Expand Down Expand Up @@ -47,9 +48,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"radio_type": "ezsp",
}

await hass.config_entries.flow.async_init(
discovery_flow.async_create_flow(
hass,
"zha",
context={"source": "hardware"},
context={"source": SOURCE_HARDWARE},
data=hw_discovery_data,
)

Expand Down
2 changes: 2 additions & 0 deletions homeassistant/config_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
SOURCE_BLUETOOTH = "bluetooth"
SOURCE_DHCP = "dhcp"
SOURCE_DISCOVERY = "discovery"
SOURCE_HARDWARE = "hardware"
SOURCE_HASSIO = "hassio"
SOURCE_HOMEKIT = "homekit"
SOURCE_IMPORT = "import"
Expand Down Expand Up @@ -159,6 +160,7 @@ def recoverable(self) -> bool:
SOURCE_BLUETOOTH,
SOURCE_DHCP,
SOURCE_DISCOVERY,
SOURCE_HARDWARE,
SOURCE_HOMEKIT,
SOURCE_IMPORT,
SOURCE_INTEGRATION_DISCOVERY,
Expand Down
6 changes: 3 additions & 3 deletions tests/components/zha/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ async def test_hardware(onboarded, hass: HomeAssistant) -> None:
"homeassistant.components.onboarding.async_is_onboarded", return_value=onboarded
):
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:
Expand Down Expand Up @@ -1029,7 +1029,7 @@ async def test_hardware_already_setup(hass: HomeAssistant) -> None:
},
}
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
Expand All @@ -1043,7 +1043,7 @@ async def test_hardware_invalid_data(hass: HomeAssistant, data) -> None:
"""Test onboarding flow -- invalid data."""

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
Expand Down

0 comments on commit 4624c85

Please sign in to comment.