mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Remove confirm screen after Z-Wave usb discovery (#145682)
* Remove confirm screen after Z-Wave usb discovery * Simplify async_step_usb
This commit is contained in:
parent
2189dc3e2a
commit
2605fda185
@ -170,8 +170,6 @@ class ZWaveJSConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
VERSION = 1
|
||||
|
||||
_title: str
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""Set up flow instance."""
|
||||
self.s0_legacy_key: str | None = None
|
||||
@ -446,7 +444,7 @@ class ZWaveJSConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
# 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(
|
||||
self._reconfigure_config_entry = next(
|
||||
(
|
||||
entry
|
||||
for entry in current_config_entries
|
||||
@ -454,7 +452,7 @@ class ZWaveJSConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
),
|
||||
None,
|
||||
)
|
||||
if not config_entry:
|
||||
if not self._reconfigure_config_entry:
|
||||
return self.async_abort(reason="addon_required")
|
||||
|
||||
vid = discovery_info.vid
|
||||
@ -503,31 +501,9 @@ class ZWaveJSConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
)
|
||||
title = human_name.split(" - ")[0].strip()
|
||||
self.context["title_placeholders"] = {CONF_NAME: title}
|
||||
self._title = title
|
||||
return await self.async_step_usb_confirm()
|
||||
|
||||
async def async_step_usb_confirm(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> ConfigFlowResult:
|
||||
"""Handle USB Discovery confirmation."""
|
||||
if user_input is None:
|
||||
return self.async_show_form(
|
||||
step_id="usb_confirm",
|
||||
description_placeholders={CONF_NAME: self._title},
|
||||
)
|
||||
|
||||
self._usb_discovery = True
|
||||
if current_config_entries := self._async_current_entries(include_ignore=False):
|
||||
self._reconfigure_config_entry = next(
|
||||
(
|
||||
entry
|
||||
for entry in current_config_entries
|
||||
if entry.data.get(CONF_USE_ADDON)
|
||||
),
|
||||
None,
|
||||
)
|
||||
if not self._reconfigure_config_entry:
|
||||
return self.async_abort(reason="addon_required")
|
||||
if current_config_entries:
|
||||
return await self.async_step_intent_migrate()
|
||||
|
||||
return await self.async_step_installation_type()
|
||||
|
@ -98,9 +98,6 @@
|
||||
"start_addon": {
|
||||
"title": "The Z-Wave add-on is starting."
|
||||
},
|
||||
"usb_confirm": {
|
||||
"description": "Do you want to set up {name} with the Z-Wave add-on?"
|
||||
},
|
||||
"zeroconf_confirm": {
|
||||
"description": "Do you want to add the Z-Wave Server with home ID {home_id} found at {url} to Home Assistant?",
|
||||
"title": "Discovered Z-Wave Server"
|
||||
|
@ -585,8 +585,8 @@ async def test_abort_hassio_discovery_with_existing_flow(hass: HomeAssistant) ->
|
||||
context={"source": config_entries.SOURCE_USB},
|
||||
data=USB_DISCOVERY_INFO,
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "usb_confirm"
|
||||
assert result["type"] is FlowResultType.MENU
|
||||
assert result["step_id"] == "installation_type"
|
||||
|
||||
result2 = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
@ -664,13 +664,8 @@ async def test_usb_discovery(
|
||||
context={"source": config_entries.SOURCE_USB},
|
||||
data=usb_discovery_info,
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "usb_confirm"
|
||||
assert result["description_placeholders"] == {"name": discovery_name}
|
||||
|
||||
assert mock_usb_serial_by_id.call_count == 1
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
|
||||
|
||||
assert result["type"] is FlowResultType.MENU
|
||||
assert result["step_id"] == "installation_type"
|
||||
assert result["menu_options"] == ["intent_recommended", "intent_custom"]
|
||||
@ -771,12 +766,8 @@ async def test_usb_discovery_addon_not_running(
|
||||
context={"source": config_entries.SOURCE_USB},
|
||||
data=USB_DISCOVERY_INFO,
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "usb_confirm"
|
||||
|
||||
assert mock_usb_serial_by_id.call_count == 2
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
|
||||
|
||||
assert result["type"] is FlowResultType.MENU
|
||||
assert result["step_id"] == "installation_type"
|
||||
|
||||
@ -932,12 +923,8 @@ async def test_usb_discovery_migration(
|
||||
context={"source": config_entries.SOURCE_USB},
|
||||
data=USB_DISCOVERY_INFO,
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "usb_confirm"
|
||||
|
||||
assert mock_usb_serial_by_id.call_count == 2
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "intent_migrate"
|
||||
|
||||
@ -1063,12 +1050,8 @@ async def test_usb_discovery_migration_restore_driver_ready_timeout(
|
||||
context={"source": config_entries.SOURCE_USB},
|
||||
data=USB_DISCOVERY_INFO,
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "usb_confirm"
|
||||
|
||||
assert mock_usb_serial_by_id.call_count == 2
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "intent_migrate"
|
||||
|
||||
@ -1366,16 +1349,16 @@ async def test_usb_discovery_with_existing_usb_flow(hass: HomeAssistant) -> None
|
||||
data=first_usb_info,
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "usb_confirm"
|
||||
assert result["type"] is FlowResultType.MENU
|
||||
assert result["step_id"] == "installation_type"
|
||||
|
||||
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"
|
||||
assert result2["type"] is FlowResultType.MENU
|
||||
assert result2["step_id"] == "installation_type"
|
||||
|
||||
usb_flows_in_progress = hass.config_entries.flow.async_progress_by_handler(
|
||||
DOMAIN, match_context={"source": config_entries.SOURCE_USB}
|
||||
@ -1409,53 +1392,6 @@ async def test_abort_usb_discovery_addon_required(hass: HomeAssistant) -> None:
|
||||
assert result["reason"] == "addon_required"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures(
|
||||
"supervisor",
|
||||
"addon_running",
|
||||
)
|
||||
async def test_abort_usb_discovery_confirm_addon_required(
|
||||
hass: HomeAssistant,
|
||||
addon_options: dict[str, Any],
|
||||
mock_usb_serial_by_id: MagicMock,
|
||||
) -> None:
|
||||
"""Test usb discovery confirm aborted when existing entry not using add-on."""
|
||||
addon_options["device"] = "/dev/another_device"
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={
|
||||
"url": "ws://localhost:3000",
|
||||
"usb_path": "/dev/another_device",
|
||||
"use_addon": True,
|
||||
},
|
||||
title=TITLE,
|
||||
unique_id="1234",
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_USB},
|
||||
data=USB_DISCOVERY_INFO,
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "usb_confirm"
|
||||
assert mock_usb_serial_by_id.call_count == 2
|
||||
|
||||
hass.config_entries.async_update_entry(
|
||||
entry,
|
||||
data={
|
||||
**entry.data,
|
||||
"use_addon": False,
|
||||
},
|
||||
)
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "addon_required"
|
||||
|
||||
|
||||
async def test_usb_discovery_requires_supervisor(hass: HomeAssistant) -> None:
|
||||
"""Test usb discovery flow is aborted when there is no supervisor."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
@ -4635,13 +4571,8 @@ async def test_recommended_usb_discovery(
|
||||
context={"source": config_entries.SOURCE_USB},
|
||||
data=usb_discovery_info,
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "usb_confirm"
|
||||
assert result["description_placeholders"] == {"name": discovery_name}
|
||||
|
||||
assert mock_usb_serial_by_id.call_count == 1
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
|
||||
|
||||
assert result["type"] is FlowResultType.MENU
|
||||
assert result["step_id"] == "installation_type"
|
||||
assert result["menu_options"] == ["intent_recommended", "intent_custom"]
|
||||
|
Loading…
x
Reference in New Issue
Block a user