diff --git a/homeassistant/backup_restore.py b/homeassistant/backup_restore.py index 6cf96fdfa91d19..32991dfb2d3b18 100644 --- a/homeassistant/backup_restore.py +++ b/homeassistant/backup_restore.py @@ -30,11 +30,11 @@ def restore_backup_file_content(config_dir: Path) -> RestoreBackupFileContent | """Return the contents of the restore backup file.""" instruction_path = config_dir.joinpath(RESTORE_BACKUP_FILE) try: - instruction_content = instruction_path.read_text(encoding="utf-8") + instruction_content = json.loads(instruction_path.read_text(encoding="utf-8")) return RestoreBackupFileContent( - backup_file_path=Path(instruction_content.split(";")[0]) + backup_file_path=Path(instruction_content["path"]) ) - except FileNotFoundError: + except (FileNotFoundError, json.JSONDecodeError): return None diff --git a/homeassistant/components/backup/manager.py b/homeassistant/components/backup/manager.py index 8120e3a6e66a6b..b3cb69861b9874 100644 --- a/homeassistant/components/backup/manager.py +++ b/homeassistant/components/backup/manager.py @@ -308,7 +308,7 @@ async def async_restore_backup(self, slug: str, **kwargs: Any) -> None: def _write_restore_file() -> None: """Write the restore file.""" Path(self.hass.config.path(RESTORE_BACKUP_FILE)).write_text( - f"{backup.path.as_posix()};", + json.dumps({"path": backup.path.as_posix()}), encoding="utf-8", ) diff --git a/tests/components/backup/test_manager.py b/tests/components/backup/test_manager.py index a269a3f2f17933..a4dba5c6936d6b 100644 --- a/tests/components/backup/test_manager.py +++ b/tests/components/backup/test_manager.py @@ -350,7 +350,7 @@ async def test_async_trigger_restore( patch("homeassistant.core.ServiceRegistry.async_call") as mocked_service_call, ): await manager.async_restore_backup(TEST_BACKUP.slug) - assert mocked_write_text.call_args[0][0] == "abc123.tar;" + assert mocked_write_text.call_args[0][0] == '{"path": "abc123.tar"}' assert mocked_service_call.called diff --git a/tests/test_backup_restore.py b/tests/test_backup_restore.py index fabb403468d9ac..44a05c0540e527 100644 --- a/tests/test_backup_restore.py +++ b/tests/test_backup_restore.py @@ -15,15 +15,10 @@ ("side_effect", "content", "expected"), [ (FileNotFoundError, "", None), - (None, "", backup_restore.RestoreBackupFileContent(backup_file_path=Path(""))), + (None, "", None), ( None, - "test;", - backup_restore.RestoreBackupFileContent(backup_file_path=Path("test")), - ), - ( - None, - "test;;;;", + '{"path": "test"}', backup_restore.RestoreBackupFileContent(backup_file_path=Path("test")), ), ],