mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Fix Z-Wave USB discovery already configured (#143907)
Fix zwave usb discovery already configured
This commit is contained in:
parent
c3dac50f21
commit
eabf88e3c9
@ -428,7 +428,15 @@ class ZWaveJSConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
"""Handle USB Discovery."""
|
"""Handle USB Discovery."""
|
||||||
if not is_hassio(self.hass):
|
if not is_hassio(self.hass):
|
||||||
return self.async_abort(reason="discovery_requires_supervisor")
|
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")
|
return self.async_abort(reason="already_in_progress")
|
||||||
if current_config_entries := self._async_current_entries(include_ignore=False):
|
if current_config_entries := self._async_current_entries(include_ignore=False):
|
||||||
config_entry = next(
|
config_entry = next(
|
||||||
|
@ -1200,6 +1200,41 @@ async def test_abort_usb_discovery_with_existing_flow(
|
|||||||
assert result2["reason"] == "already_in_progress"
|
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(
|
async def test_abort_usb_discovery_addon_required(
|
||||||
hass: HomeAssistant, supervisor, addon_options
|
hass: HomeAssistant, supervisor, addon_options
|
||||||
) -> None:
|
) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user