mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +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
|
VERSION = 1
|
||||||
|
|
||||||
_title: str
|
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
"""Set up flow instance."""
|
"""Set up flow instance."""
|
||||||
self.s0_legacy_key: str | None = None
|
self.s0_legacy_key: str | None = None
|
||||||
@ -446,7 +444,7 @@ class ZWaveJSConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
# at least for a short time.
|
# 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(
|
self._reconfigure_config_entry = next(
|
||||||
(
|
(
|
||||||
entry
|
entry
|
||||||
for entry in current_config_entries
|
for entry in current_config_entries
|
||||||
@ -454,7 +452,7 @@ class ZWaveJSConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
),
|
),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
if not config_entry:
|
if not self._reconfigure_config_entry:
|
||||||
return self.async_abort(reason="addon_required")
|
return self.async_abort(reason="addon_required")
|
||||||
|
|
||||||
vid = discovery_info.vid
|
vid = discovery_info.vid
|
||||||
@ -503,31 +501,9 @@ class ZWaveJSConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
)
|
)
|
||||||
title = human_name.split(" - ")[0].strip()
|
title = human_name.split(" - ")[0].strip()
|
||||||
self.context["title_placeholders"] = {CONF_NAME: title}
|
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
|
self._usb_discovery = True
|
||||||
if current_config_entries := self._async_current_entries(include_ignore=False):
|
if current_config_entries:
|
||||||
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")
|
|
||||||
return await self.async_step_intent_migrate()
|
return await self.async_step_intent_migrate()
|
||||||
|
|
||||||
return await self.async_step_installation_type()
|
return await self.async_step_installation_type()
|
||||||
|
@ -98,9 +98,6 @@
|
|||||||
"start_addon": {
|
"start_addon": {
|
||||||
"title": "The Z-Wave add-on is starting."
|
"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": {
|
"zeroconf_confirm": {
|
||||||
"description": "Do you want to add the Z-Wave Server with home ID {home_id} found at {url} to Home Assistant?",
|
"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"
|
"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},
|
context={"source": config_entries.SOURCE_USB},
|
||||||
data=USB_DISCOVERY_INFO,
|
data=USB_DISCOVERY_INFO,
|
||||||
)
|
)
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.MENU
|
||||||
assert result["step_id"] == "usb_confirm"
|
assert result["step_id"] == "installation_type"
|
||||||
|
|
||||||
result2 = await hass.config_entries.flow.async_init(
|
result2 = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
@ -664,13 +664,8 @@ async def test_usb_discovery(
|
|||||||
context={"source": config_entries.SOURCE_USB},
|
context={"source": config_entries.SOURCE_USB},
|
||||||
data=usb_discovery_info,
|
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
|
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["type"] is FlowResultType.MENU
|
||||||
assert result["step_id"] == "installation_type"
|
assert result["step_id"] == "installation_type"
|
||||||
assert result["menu_options"] == ["intent_recommended", "intent_custom"]
|
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},
|
context={"source": config_entries.SOURCE_USB},
|
||||||
data=USB_DISCOVERY_INFO,
|
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
|
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["type"] is FlowResultType.MENU
|
||||||
assert result["step_id"] == "installation_type"
|
assert result["step_id"] == "installation_type"
|
||||||
|
|
||||||
@ -932,12 +923,8 @@ async def test_usb_discovery_migration(
|
|||||||
context={"source": config_entries.SOURCE_USB},
|
context={"source": config_entries.SOURCE_USB},
|
||||||
data=USB_DISCOVERY_INFO,
|
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
|
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["type"] is FlowResultType.FORM
|
||||||
assert result["step_id"] == "intent_migrate"
|
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},
|
context={"source": config_entries.SOURCE_USB},
|
||||||
data=USB_DISCOVERY_INFO,
|
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
|
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["type"] is FlowResultType.FORM
|
||||||
assert result["step_id"] == "intent_migrate"
|
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,
|
data=first_usb_info,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.MENU
|
||||||
assert result["step_id"] == "usb_confirm"
|
assert result["step_id"] == "installation_type"
|
||||||
|
|
||||||
result2 = await hass.config_entries.flow.async_init(
|
result2 = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={"source": config_entries.SOURCE_USB},
|
context={"source": config_entries.SOURCE_USB},
|
||||||
data=USB_DISCOVERY_INFO,
|
data=USB_DISCOVERY_INFO,
|
||||||
)
|
)
|
||||||
assert result2["type"] is FlowResultType.FORM
|
assert result2["type"] is FlowResultType.MENU
|
||||||
assert result2["step_id"] == "usb_confirm"
|
assert result2["step_id"] == "installation_type"
|
||||||
|
|
||||||
usb_flows_in_progress = hass.config_entries.flow.async_progress_by_handler(
|
usb_flows_in_progress = hass.config_entries.flow.async_progress_by_handler(
|
||||||
DOMAIN, match_context={"source": config_entries.SOURCE_USB}
|
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"
|
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:
|
async def test_usb_discovery_requires_supervisor(hass: HomeAssistant) -> None:
|
||||||
"""Test usb discovery flow is aborted when there is no supervisor."""
|
"""Test usb discovery flow is aborted when there is no supervisor."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
@ -4635,13 +4571,8 @@ async def test_recommended_usb_discovery(
|
|||||||
context={"source": config_entries.SOURCE_USB},
|
context={"source": config_entries.SOURCE_USB},
|
||||||
data=usb_discovery_info,
|
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
|
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["type"] is FlowResultType.MENU
|
||||||
assert result["step_id"] == "installation_type"
|
assert result["step_id"] == "installation_type"
|
||||||
assert result["menu_options"] == ["intent_recommended", "intent_custom"]
|
assert result["menu_options"] == ["intent_recommended", "intent_custom"]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user