Fix Z-Wave USB discovery already configured (#143907)

Fix zwave usb discovery already configured
This commit is contained in:
Martin Hjelmare 2025-04-30 07:40:18 +02:00 committed by GitHub
parent c3dac50f21
commit eabf88e3c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 44 additions and 1 deletions

View File

@ -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(

View File

@ -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: