Fix returned value from backup/info WS command (#67439)

This commit is contained in:
Joakim Sørensen 2022-03-01 21:37:51 +01:00 committed by GitHub
parent 94130a6060
commit e58ce7ab6e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 5 deletions

View file

@ -5,6 +5,7 @@ from dataclasses import asdict, dataclass
import hashlib import hashlib
import json import json
from pathlib import Path from pathlib import Path
import tarfile
from tarfile import TarError from tarfile import TarError
from tempfile import TemporaryDirectory from tempfile import TemporaryDirectory
@ -51,7 +52,7 @@ class BackupManager:
def _read_backups() -> None: def _read_backups() -> None:
for backup_path in self.backup_dir.glob("*.tar"): for backup_path in self.backup_dir.glob("*.tar"):
try: try:
with SecureTarFile(backup_path, "r", gzip=False) as backup_file: with tarfile.open(backup_path, "r:") as backup_file:
if data_file := backup_file.extractfile("./backup.json"): if data_file := backup_file.extractfile("./backup.json"):
data = json.loads(data_file.read()) data = json.loads(data_file.read())
backup = Backup( backup = Backup(

View file

@ -30,7 +30,7 @@ async def handle_info(
connection.send_result( connection.send_result(
msg["id"], msg["id"],
{ {
"backups": list(backups), "backups": list(backups.values()),
"backing_up": manager.backing_up, "backing_up": manager.backing_up,
}, },
) )

View file

@ -20,12 +20,17 @@ async def test_info(
client = await hass_ws_client(hass) client = await hass_ws_client(hass)
await hass.async_block_till_done() await hass.async_block_till_done()
with patch(
"homeassistant.components.backup.websocket.BackupManager.get_backups",
return_value={TEST_BACKUP.slug: TEST_BACKUP},
):
await client.send_json({"id": 1, "type": "backup/info"}) await client.send_json({"id": 1, "type": "backup/info"})
msg = await client.receive_json() msg = await client.receive_json()
assert msg["id"] == 1 assert msg["id"] == 1
assert msg["success"] assert msg["success"]
assert msg["result"] == {"backing_up": False, "backups": []} assert msg["result"] == {"backing_up": False, "backups": [TEST_BACKUP.as_dict()]}
async def test_remove( async def test_remove(