diff --git a/homeassistant/components/zwave_js/config_flow.py b/homeassistant/components/zwave_js/config_flow.py index 46d9e061f0b..84717047fdd 100644 --- a/homeassistant/components/zwave_js/config_flow.py +++ b/homeassistant/components/zwave_js/config_flow.py @@ -907,10 +907,6 @@ class ZWaveJSConfigFlow(ConfigFlow, domain=DOMAIN): """Reset the current controller, and instruct the user to unplug it.""" if user_input is not None: - config_entry = self._reconfigure_config_entry - assert config_entry is not None - # Unload the config entry before stopping the add-on. - await self.hass.config_entries.async_unload(config_entry.entry_id) if self.usb_path: # USB discovery was used, so the device is already known. await self._async_set_addon_config({CONF_ADDON_DEVICE: self.usb_path}) @@ -925,6 +921,11 @@ class ZWaveJSConfigFlow(ConfigFlow, domain=DOMAIN): _LOGGER.error("Failed to reset controller: %s", err) return self.async_abort(reason="reset_failed") + config_entry = self._reconfigure_config_entry + assert config_entry is not None + # Unload the config entry before asking the user to unplug the controller. + await self.hass.config_entries.async_unload(config_entry.entry_id) + return self.async_show_form( step_id="instruct_unplug", description_placeholders={ diff --git a/tests/components/zwave_js/test_config_flow.py b/tests/components/zwave_js/test_config_flow.py index de76d9d9dc4..15fd9fcbd30 100644 --- a/tests/components/zwave_js/test_config_flow.py +++ b/tests/components/zwave_js/test_config_flow.py @@ -1109,10 +1109,10 @@ async def test_usb_discovery_migration_driver_ready_timeout( assert result["type"] == FlowResultType.FORM assert result["step_id"] == "instruct_unplug" + assert entry.state is config_entries.ConfigEntryState.NOT_LOADED result = await hass.config_entries.flow.async_configure(result["flow_id"], {}) - assert entry.state is config_entries.ConfigEntryState.NOT_LOADED assert result["type"] == FlowResultType.SHOW_PROGRESS assert result["step_id"] == "start_addon" assert set_addon_options.call_args == call( @@ -3776,6 +3776,7 @@ async def test_reconfigure_migrate_with_addon( assert result["type"] == FlowResultType.FORM assert result["step_id"] == "instruct_unplug" + assert entry.state is config_entries.ConfigEntryState.NOT_LOADED result = await hass.config_entries.flow.async_configure(result["flow_id"], {}) @@ -3790,7 +3791,6 @@ async def test_reconfigure_migrate_with_addon( }, ) - assert entry.state is config_entries.ConfigEntryState.NOT_LOADED assert result["type"] == FlowResultType.SHOW_PROGRESS assert result["step_id"] == "start_addon" assert set_addon_options.call_args == call( @@ -3918,6 +3918,7 @@ async def test_reconfigure_migrate_driver_ready_timeout( assert result["type"] == FlowResultType.FORM assert result["step_id"] == "instruct_unplug" + assert entry.state is config_entries.ConfigEntryState.NOT_LOADED result = await hass.config_entries.flow.async_configure(result["flow_id"], {}) @@ -3932,7 +3933,6 @@ async def test_reconfigure_migrate_driver_ready_timeout( }, ) - assert entry.state is config_entries.ConfigEntryState.NOT_LOADED assert result["type"] == FlowResultType.SHOW_PROGRESS assert result["step_id"] == "start_addon" assert set_addon_options.call_args == call( @@ -4108,6 +4108,7 @@ async def test_reconfigure_migrate_start_addon_failure( assert result["type"] == FlowResultType.FORM assert result["step_id"] == "instruct_unplug" + assert entry.state is config_entries.ConfigEntryState.NOT_LOADED result = await hass.config_entries.flow.async_configure(result["flow_id"], {}) @@ -4202,6 +4203,7 @@ async def test_reconfigure_migrate_restore_failure( assert result["type"] == FlowResultType.FORM assert result["step_id"] == "instruct_unplug" + assert entry.state is config_entries.ConfigEntryState.NOT_LOADED result = await hass.config_entries.flow.async_configure(result["flow_id"], {}) @@ -4367,6 +4369,7 @@ async def test_choose_serial_port_usb_ports_failure( assert result["type"] == FlowResultType.FORM assert result["step_id"] == "instruct_unplug" + assert entry.state is config_entries.ConfigEntryState.NOT_LOADED with patch( "homeassistant.components.zwave_js.config_flow.async_get_usb_ports",