8000 Remove confirm screen after Z-Wave usb discovery (#145682) · home-assistant/core@bfa919d · GitHub
[go: up one dir, main page]

Skip to content

Commit bfa919d

Browse files
MindFreezebramkragten
authored andcommitted
Remove confirm screen after Z-Wave usb discovery (#145682)
* Remove confirm screen after Z-Wave usb discovery * Simplify async_step_usb
1 parent f09c28e commit bfa919d

File tree

3 files changed

+14
-110
lines changed

3 files changed

+14
-110
lines changed

homeassistant/components/zwave_js/config_flow.py

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ class ZWaveJSConfigFlow(ConfigFlow, domain=DOMAIN):
170170

171171
VERSION = 1
172172

173-
_title: str
174-
175173
def __init__(self) -> None:
176174
"""Set up flow instance."""
177175
self.s0_legacy_key: str | None = None
@@ -446,15 +444,15 @@ async def async_step_usb(self, discovery_info: UsbServiceInfo) -> ConfigFlowResu
446444
# at least for a short time.
447445
return self.async_abort(reason="already_in_progress")
448446
if current_config_entries := self._async_current_entries(include_ignore=False):
449-
config_entry = next(
447+
self._reconfigure_config_entry = next(
450448
(
451449
entry
452450
for entry in current_config_entries
453451
if entry.data.get(CONF_USE_ADDON)
454452
),
455453
None,
456454
)
457-
if not config_entry:
455+
if not self._reconfigure_config_entry:
458456
return self.async_abort(reason="addon_required")
459457

460458
vid = discovery_info.vid
@@ -503,31 +501,9 @@ async def async_step_usb(self, discovery_info: UsbServiceInfo) -> ConfigFlowResu
503501
)
504502
title = human_name.split(" - ")[0].strip()
505503
self.context["title_placeholders"] = {CONF_NAME: title}
506-
self._title = title
507-
return await self.async_step_usb_confirm()
508-
509-
async def async_step_usb_confirm(
510-
self, user_input: dict[str, Any] | None = None
511-
) -> ConfigFlowResult:
512-
"""Handle USB Discovery confirmation."""
513-
if user_input is None:
514-
return self.async_show_form(
515-
step_id="usb_confirm",
516-
description_placeholders={CONF_NAME: self._title},
517-
)
518504

519505
self._usb_discovery = True
520-
if current_config_entries := self._async_current_entries(include_ignore=False):
521-
self._reconfigure_config_entry = next(
522-
(
523-
entry
524-
for entry in current_config_entries
525-
if entry.data.get(CONF_USE_ADDON)
526-
),
527-
None,
528-
)
529-
if not self._reconfigure_config_entry:
530-
return self.async_abort(reason="addon_required")
506+
if current_config_entries:
531507
return await self.async_step_intent_migrate()
532508

533509
return await self.async_step_installation_type()

homeassistant/components/zwave_js/strings.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,6 @@
9898
"start_addon": {
9999
"title": "The Z-Wave add-on is starting."
100100
},
101-
"usb_confirm": {
102-
"description": "Do you want to set up {name} with the Z-Wave add-on?"
103-
},
104101
"zeroconf_confirm": {
105102
"description": "Do you want to add the Z-Wave Server with home ID {home_id} found at {url} to Home Assistant?",
106103
"title": "Discovered Z-Wave Server"

tests/components/zwave_js/test_config_flow.py

Lines changed: 11 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,8 @@ async def test_abort_hassio_discovery_with_existing_flow(hass: HomeAssistant) ->
585585
context={"source": config_entries.SOURCE_USB},
586586
data=USB_DISCOVERY_INFO,
587587
)
588-
assert result["type"] is FlowResultType.FORM
589-
assert result["step_id"] == "usb_confirm"
588+
assert result["type"] is FlowResultType.MENU
589+
assert result["step_id"] == "installation_type"
590590

591591
result2 = await hass.config_entries.flow.async_init(
592592
DOMAIN,
@@ -664,13 +664,8 @@ async def test_usb_discovery(
664664
context={"source": config_entries.SOURCE_USB},
665665
data=usb_discovery_info,
666666
)
667-
assert result["type"] is FlowResultType.FORM
668-
assert result["step_id"] == "usb_confirm"
669-
assert result["description_placeholders"] == {"name": discovery_name}
670-
assert mock_usb_serial_by_id.call_count == 1
671-
672-
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
673667

668+
assert mock_usb_serial_by_id.call_count == 1
674669
assert result["type"] is FlowResultType.MENU
675670
assert result["step_id"] == "installation_type"
676671
assert result["menu_options"] == ["intent_recommended", "intent_custom"]
@@ -771,12 +766,8 @@ async def test_usb_discovery_addon_not_running(
771766
context={"source": config_entries.SOURCE_USB},
772767
data=USB_DISCOVERY_INFO,
773768
)
774-
assert result["type"] is FlowResultType.FORM
775-
assert result["step_id"] == "usb_confirm"
776-
assert mock_usb_serial_by_id.call_count == 2
777-
778-
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
779769

770+
assert mock_usb_serial_by_id.call_count == 2
780771
assert result["type"] is FlowResultType.MENU
781772
assert result["step_id"] == "installation_type"
782773

@@ -932,12 +923,8 @@ async def mock_restore_nvm(data: bytes):
932923
context={"source": config_entries.SOURCE_USB},
933924
data=USB_DISCOVERY_INFO,
934925
)
935-
assert result["type"] is FlowResultType.FORM
936-
assert result["step_id"] == "usb_confirm"
937-
assert mock_usb_serial_by_id.call_count == 2
938-
939-
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
940926

927+
assert mock_usb_serial_by_id.call_count == 2
941928
assert result["type"] is FlowResultType.FORM
942929
assert result["step_id"] == "intent_migrate"
943930

@@ -1063,12 +1050,8 @@ async def mock_restore_nvm(data: bytes):
10631050
context={"source": config_entries.SOURCE_USB},
10641051
data=USB_DISCOVERY_INFO,
10651052
)
1066-
assert result["type"] is FlowResultType.FORM
1067-
assert result["step_id"] == "usb_confirm"
1068-
assert mock_usb_serial_by_id.call_count == 2
1069-
1070-
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
10711053

1054+
assert mock_usb_serial_by_id.call_count == 2
10721055
assert result["type"] is FlowResultType.FORM
10731056
assert result["step_id"] == "intent_migrate"
10741057

@@ -1366,16 +1349,16 @@ async def test_usb_discovery_with_existing_usb_flow(hass: HomeAssistant) -> None
13661349
data=first_usb_info,
13671350
)
13681351

1369-
assert result["type"] is FlowResultType.FORM
1370-
assert result["step_id"] == "usb_confirm"
1352+
assert result["type"] is FlowResultType.MENU
1353+
assert result["step_id"] == "installation_type"
13711354

13721355
result2 = await hass.config_entries.flow.async_init(
13731356
DOMAIN,
13741357
context={"source": config_entries.SOURCE_USB},
13751358
data=USB_DISCOVERY_INFO,
13761359
)
1377-
assert result2["type"] is FlowResultType.FORM
1378-
assert result2["step_id"] == "usb_confirm"
1360+
assert result2["type"] is FlowResultType.MENU
1361+
assert result2["step_id"] == "installation_type"
13791362

13801363
usb_flows_in_progress = hass.config_entries.flow.async_progress_by_handler(
13811364
DOMAIN, match_context={"source": config_entries.SOURCE_USB}
@@ -1409,53 +1392,6 @@ async def test_abort_usb_discovery_addon_required(hass: HomeAssistant) -> None:
14091392
assert result["reason"] == "addon_required"
14101393

14111394

1412-
@pytest.mark.usefixtures(
1413-
"supervisor",
1414-
"addon_running",
1415-
)
1416-
async def test_abort_usb_discovery_confirm_addon_required(
1417-
hass: HomeAssistant,
1418-
addon_options: dict[str, Any],
1419-
mock_usb_serial_by_id: MagicMock,
1420-
) -> None:
1421-
"""Test usb discovery confirm aborted when existing entry not using add-on."""
1422-
addon_options["device"] = "/dev/another_device"
1423-
entry = MockConfigEntry(
1424-
domain=DOMAIN,
1425-
data={
1426-
"url": "ws://localhost:3000",
1427-
"usb_path": "/dev/another_device",
1428-
"use_addon": True,
1429-
},
1430-
title=TITLE,
1431-
unique_id="1234",
1432-
)
1433-
entry.add_to_hass(hass)
1434-
1435-
result = await hass.config_entries.flow.async_init(
1436-
DOMAIN,
1437-
context={"source": config_entries.SOURCE_USB},
1438-
data=USB_DISCOVERY_INFO,
1439-
)
1440-
1441-
assert result["type"] is FlowResultType.FORM
1442-
assert result["step_id"] == "usb_confirm"
1443-
assert mock_usb_serial_by_id.call_count == 2
1444-
1445-
hass.config_entries.async_update_entry(
1446-
entry,
1447-
data={
1448-
**entry.data,
1449-
"use_addon": False,
1450-
},
1451-
)
1452-
1453-
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
1454-
1455-
assert result["type"] is FlowResultType.ABORT
1456-
assert result["reason"] == "addon_required"
1457-
1458-
14591395
async def test_usb_discovery_requires_supervisor(hass: HomeAssistant) -> None:
14601396
"""Test usb discovery flow is aborted when there is no supervisor."""
14611397
result = await hass.config_entries.flow.async_init(
@@ -4635,13 +4571,8 @@ async def test_recommended_usb_discovery(
46354571
context={"source": config_entries.SOURCE_USB},
46364572
data=usb_discovery_info,
46374573
)
4638-
assert result["type"] is FlowResultType.FORM
4639-
assert result["step_id"] == "usb_confirm"
4640-
assert result["description_placeholders"] == {"name": discovery_name}
4641-
assert mock_usb_serial_by_id.call_count == 1
4642-
4643-
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
46444574

4575+
assert mock_usb_serial_by_id.call_count == 1
46454576
assert result["type"] is FlowResultType.MENU
46464577
assert result["step_id"] == "installation_type"
46474578
assert result["menu_options"] == ["intent_recommended", "intent_custom"]

0 commit comments

Comments
 (0)
0