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

pull/67456/head
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 json
from pathlib import Path
import tarfile
from tarfile import TarError
from tempfile import TemporaryDirectory
@ -51,7 +52,7 @@ class BackupManager:
def _read_backups() -> None:
for backup_path in self.backup_dir.glob("*.tar"):
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"):
data = json.loads(data_file.read())
backup = Backup(

View File

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

View File

@ -20,12 +20,17 @@ async def test_info(
client = await hass_ws_client(hass)
await hass.async_block_till_done()
await client.send_json({"id": 1, "type": "backup/info"})
msg = await client.receive_json()
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"})
msg = await client.receive_json()
assert msg["id"] == 1
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(