8000 Remove confirm screen after Z-Wave usb discovery by MindFreeze · Pull Request #145682 · home-assistant/core · GitHub
[go: up one dir, main page]

Skip to content

Remove confirm screen after Z-Wave usb discovery #145682

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
8000
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 3 additions & 27 deletions homeassistant/components/zwave_js/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -446,15 +444,15 @@ async def async_step_usb(self, discovery_info: UsbServiceInfo) -> ConfigFlowResu
# 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(
(
e 10000 ntry
for entry in current_config_entries
if entry.data.get(CONF_USE_ADDON)
),
None,
)
if not config_entry:
if not self._reconfigure_config_entry:
return self.async_abort(reason="addon_required")

vid = discovery_info.vid
Expand Down Expand Up @@ -503,31 +501,9 @@ async def async_step_usb(self, discovery_info: UsbServiceInfo) -> ConfigFlowResu
)
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()
Expand Down
3 changes: 0 additions & 3 deletions homeassistant/components/zwave_js/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
91 changes: 11 additions & 80 deletions tests/components/zwave_js/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 mock_usb_serial_by_id.call_count == 1
assert result["type"] is FlowResultType.MENU
assert result["step_id"] == "installation_type"
assert result["menu_options"] == ["intent_recommended", "intent_custom"]
Expand Down Expand Up @@ -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 mock_usb_serial_by_id.call_count == 2
assert result["type"] is FlowResultType.MENU
assert result["step_id"] == "installation_type"

Expand Down Expand Up @@ -932,12 +923,8 @@ async def mock_restore_nvm(data: bytes):
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 mock_usb_serial_by_id.call_count == 2
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "intent_migrate"

Expand Down Expand Up @@ -1063,12 +1050,8 @@ async def mock_restore_nvm(data: bytes):
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 mock_usb_serial_by_id.call_count == 2
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "intent_migrate"

Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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 mock_usb_serial_by_id.call_count == 1
assert result["type"] is FlowResultType.MENU
assert result["step_id"] == "installation_type"
assert result["menu_opt 2364 ions"] == ["intent_recommended", "intent_custom"]
Expand Down
0