diff --git a/homeassistant/components/zwave_js/config_flow.py b/homeassistant/components/zwave_js/config_flow.py index b453764aa4e..1132af86928 100644 --- a/homeassistant/components/zwave_js/config_flow.py +++ b/homeassistant/components/zwave_js/config_flow.py @@ -428,7 +428,15 @@ class ZWaveJSConfigFlow(ConfigFlow, domain=DOMAIN): """Handle USB Discovery.""" if not is_hassio(self.hass): return self.async_abort(reason="discovery_requires_supervisor") - if self._async_in_progress(): + if any( + flow + for flow in self._async_in_progress() + if flow["context"].get("source") != SOURCE_USB + ): + # Allow multiple USB discovery flows to be in progress. + # Migration requires more than one USB stick to be connected, + # which can cause more than one discovery flow to be in progress, + # at least for a short time. return self.async_abort(reason="already_in_progress") if current_config_entries := self._async_current_entries(include_ignore=False): config_entry = next( diff --git a/tests/components/zwave_js/test_config_flow.py b/tests/components/zwave_js/test_config_flow.py index c5ccd615f5c..f844c7681c7 100644 --- a/tests/components/zwave_js/test_config_flow.py +++ b/tests/components/zwave_js/test_config_flow.py @@ -1200,6 +1200,41 @@ async def test_abort_usb_discovery_with_existing_flow( assert result2["reason"] == "already_in_progress" +@pytest.mark.usefixtures("supervisor", "addon_options") +async def test_usb_discovery_with_existing_usb_flow(hass: HomeAssistant) -> None: + """Test usb discovery allows more than one USB flow in progress.""" + first_usb_info = UsbServiceInfo( + device="/dev/other_device", + pid="AAAA", + vid="AAAA", + serial_number="5678", + description="zwave radio", + manufacturer="test", + ) + result = await hass.config_entries.flow.async_init( + DOMAIN, + context={"source": config_entries.SOURCE_USB}, + data=first_usb_info, + ) + + assert result["type"] is FlowResultType.FORM + assert result["step_id"] == "usb_confirm" + + result2 = await hass.config_entries.flow.async_init( + DOMAIN, + context={"source": config_entries.SOURCE_USB}, + data=USB_DISCOVERY_INFO, + ) + assert result2["type"] is FlowResultType.FORM + assert result2["step_id"] == "usb_confirm" + + usb_flows_in_progress = hass.config_entries.flow.async_progress_by_handler( + DOMAIN, match_context={"source": config_entries.SOURCE_USB} + ) + + assert len(usb_flows_in_progress) == 2 + + async def test_abort_usb_discovery_addon_required( hass: HomeAssistant, supervisor, addon_options ) -> None: