Add retry restore step to ZWave-JS migration (#143934)

* Add retry restore step to ZWave-JS migration

* improve test
This commit is contained in:
Petar Petrov 2025-04-30 12:54:50 +03:00 committed by GitHub
parent 4ac29c6aef
commit a7af0eaccd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 35 additions and 4 deletions

View File

@ -1133,7 +1133,15 @@ class ZWaveJSConfigFlow(ConfigFlow, domain=DOMAIN):
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Restore failed."""
return self.async_abort(reason="restore_failed")
if user_input is not None:
return await self.async_step_restore_nvm()
return self.async_show_form(
step_id="restore_failed",
description_placeholders={
"file_path": str(self.backup_filepath),
},
)
async def async_step_migration_done(
self, user_input: dict[str, Any] | None = None

View File

@ -21,7 +21,6 @@
"not_zwave_js_addon": "Discovered add-on is not the official Z-Wave add-on.",
"reconfigure_successful": "[%key:common::config_flow::abort::reconfigure_successful%]",
"reset_failed": "Failed to reset controller.",
"restore_failed": "Failed to restore network.",
"usb_ports_failed": "Failed to get USB devices."
},
"error": {
@ -118,6 +117,11 @@
"title": "Unplug your old controller",
"description": "Backup saved to \"{file_path}\"\n\nYour old controller has been reset. If the hardware is no longer needed, you can now unplug it.\n\nPlease make sure your new controller is plugged in before continuing."
},
"restore_failed": {
"title": "Restoring unsuccessful",
"description": "Your Z-Wave network could not be restored to the new controller. This means that your Z-Wave devices are not connected to Home Assistant.\n\nThe backup is saved to ”{file_path}”",
"submit": "Try again"
},
"choose_serial_port": {
"data": {
"usb_path": "[%key:common::config_flow::data::usb_path%]"

View File

@ -3914,8 +3914,27 @@ async def test_reconfigure_migrate_restore_failure(
result = await hass.config_entries.flow.async_configure(result["flow_id"])
assert result["type"] == FlowResultType.ABORT
assert result["reason"] == "restore_failed"
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "restore_failed"
assert result["description_placeholders"]["file_path"]
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
assert result["type"] == FlowResultType.SHOW_PROGRESS
assert result["step_id"] == "restore_nvm"
await hass.async_block_till_done()
assert client.driver.controller.async_restore_nvm.call_count == 2
result = await hass.config_entries.flow.async_configure(result["flow_id"])
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "restore_failed"
hass.config_entries.flow.async_abort(result["flow_id"])
assert len(hass.config_entries.flow.async_progress()) == 0
async def test_get_driver_failure(hass: HomeAssistant, integration, client) -> None: