diff --git a/homeassistant/components/zwave_js/config_flow.py b/homeassistant/components/zwave_js/config_flow.py index 023baf10bd4..7b59cce36a9 100644 --- a/homeassistant/components/zwave_js/config_flow.py +++ b/homeassistant/components/zwave_js/config_flow.py @@ -301,6 +301,7 @@ class ConfigFlow(BaseZwaveJSFlow, config_entries.ConfigFlow, domain=DOMAIN): super().__init__() self.use_addon = False self._title: str | None = None + self._usb_discovery = False @property def flow_manager(self) -> config_entries.ConfigEntriesFlowManager: @@ -387,6 +388,8 @@ class ConfigFlow(BaseZwaveJSFlow, config_entries.ConfigFlow, domain=DOMAIN): data_schema=vol.Schema({}), ) + self._usb_discovery = True + return await self.async_step_on_supervisor({CONF_USE_ADDON: True}) async def async_step_manual( @@ -504,7 +507,8 @@ class ConfigFlow(BaseZwaveJSFlow, config_entries.ConfigFlow, domain=DOMAIN): self.s2_access_control_key = user_input[CONF_S2_ACCESS_CONTROL_KEY] self.s2_authenticated_key = user_input[CONF_S2_AUTHENTICATED_KEY] self.s2_unauthenticated_key = user_input[CONF_S2_UNAUTHENTICATED_KEY] - self.usb_path = user_input[CONF_USB_PATH] + if not self._usb_discovery: + self.usb_path = user_input[CONF_USB_PATH] new_addon_config = { **addon_config, @@ -534,21 +538,21 @@ class ConfigFlow(BaseZwaveJSFlow, config_entries.ConfigFlow, domain=DOMAIN): CONF_ADDON_S2_UNAUTHENTICATED_KEY, self.s2_unauthenticated_key or "" ) - data_schema = vol.Schema( - { - vol.Required(CONF_USB_PATH, default=usb_path): str, - vol.Optional(CONF_S0_LEGACY_KEY, default=s0_legacy_key): str, - vol.Optional( - CONF_S2_ACCESS_CONTROL_KEY, default=s2_access_control_key - ): str, - vol.Optional( - CONF_S2_AUTHENTICATED_KEY, default=s2_authenticated_key - ): str, - vol.Optional( - CONF_S2_UNAUTHENTICATED_KEY, default=s2_unauthenticated_key - ): str, - } - ) + schema = { + vol.Optional(CONF_S0_LEGACY_KEY, default=s0_legacy_key): str, + vol.Optional( + CONF_S2_ACCESS_CONTROL_KEY, default=s2_access_control_key + ): str, + vol.Optional(CONF_S2_AUTHENTICATED_KEY, default=s2_authenticated_key): str, + vol.Optional( + CONF_S2_UNAUTHENTICATED_KEY, default=s2_unauthenticated_key + ): str, + } + + if not self._usb_discovery: + schema = {vol.Required(CONF_USB_PATH, default=usb_path): str, **schema} + + data_schema = vol.Schema(schema) return self.async_show_form(step_id="configure_addon", data_schema=data_schema) diff --git a/tests/components/zwave_js/test_config_flow.py b/tests/components/zwave_js/test_config_flow.py index d5829283ff2..3094d10b2bd 100644 --- a/tests/components/zwave_js/test_config_flow.py +++ b/tests/components/zwave_js/test_config_flow.py @@ -475,7 +475,6 @@ async def test_usb_discovery( result = await hass.config_entries.flow.async_configure( result["flow_id"], { - "usb_path": "/test", "s0_legacy_key": "new123", "s2_access_control_key": "new456", "s2_authenticated_key": "new789", @@ -488,7 +487,7 @@ async def test_usb_discovery( "core_zwave_js", { "options": { - "device": "/test", + "device": USB_DISCOVERY_INFO["device"], "s0_legacy_key": "new123", "s2_access_control_key": "new456", "s2_authenticated_key": "new789", @@ -516,7 +515,7 @@ async def test_usb_discovery( assert result["title"] == TITLE assert result["data"] == { "url": "ws://host1:3001", - "usb_path": "/test", + "usb_path": USB_DISCOVERY_INFO["device"], "s0_legacy_key": "new123", "s2_access_control_key": "new456", "s2_authenticated_key": "new789", @@ -557,7 +556,6 @@ async def test_usb_discovery_addon_not_running( # Make sure the discovered usb device is preferred. data_schema = result["data_schema"] assert data_schema({}) == { - "usb_path": USB_DISCOVERY_INFO["device"], "s0_legacy_key": "", "s2_access_control_key": "", "s2_authenticated_key": "", @@ -567,7 +565,6 @@ async def test_usb_discovery_addon_not_running( result = await hass.config_entries.flow.async_configure( result["flow_id"], { - "usb_path": USB_DISCOVERY_INFO["device"], "s0_legacy_key": "new123", "s2_access_control_key": "new456", "s2_authenticated_key": "new789",