mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 14:57:09 +00:00
Use JSON as format for .HA_RESTORE (#129792)
* Use JSON as format for .HA_RESTORE * Adjust bakup manager test
This commit is contained in:
parent
ae06f734ce
commit
3cadc1796f
@ -30,11 +30,11 @@ def restore_backup_file_content(config_dir: Path) -> RestoreBackupFileContent |
|
|||||||
"""Return the contents of the restore backup file."""
|
"""Return the contents of the restore backup file."""
|
||||||
instruction_path = config_dir.joinpath(RESTORE_BACKUP_FILE)
|
instruction_path = config_dir.joinpath(RESTORE_BACKUP_FILE)
|
||||||
try:
|
try:
|
||||||
instruction_content = instruction_path.read_text(encoding="utf-8")
|
instruction_content = json.loads(instruction_path.read_text(encoding="utf-8"))
|
||||||
return RestoreBackupFileContent(
|
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
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
@ -308,7 +308,7 @@ class BackupManager(BaseBackupManager):
|
|||||||
def _write_restore_file() -> None:
|
def _write_restore_file() -> None:
|
||||||
"""Write the restore file."""
|
"""Write the restore file."""
|
||||||
Path(self.hass.config.path(RESTORE_BACKUP_FILE)).write_text(
|
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",
|
encoding="utf-8",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -350,7 +350,7 @@ async def test_async_trigger_restore(
|
|||||||
patch("homeassistant.core.ServiceRegistry.async_call") as mocked_service_call,
|
patch("homeassistant.core.ServiceRegistry.async_call") as mocked_service_call,
|
||||||
):
|
):
|
||||||
await manager.async_restore_backup(TEST_BACKUP.slug)
|
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
|
assert mocked_service_call.called
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,15 +15,10 @@ from .common import get_test_config_dir
|
|||||||
("side_effect", "content", "expected"),
|
("side_effect", "content", "expected"),
|
||||||
[
|
[
|
||||||
(FileNotFoundError, "", None),
|
(FileNotFoundError, "", None),
|
||||||
(None, "", backup_restore.RestoreBackupFileContent(backup_file_path=Path(""))),
|
(None, "", None),
|
||||||
(
|
(
|
||||||
None,
|
None,
|
||||||
"test;",
|
'{"path": "test"}',
|
||||||
backup_restore.RestoreBackupFileContent(backup_file_path=Path("test")),
|
|
||||||
),
|
|
||||||
(
|
|
||||||
None,
|
|
||||||
"test;;;;",
|
|
||||||
backup_restore.RestoreBackupFileContent(backup_file_path=Path("test")),
|
backup_restore.RestoreBackupFileContent(backup_file_path=Path("test")),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user