Skip to content

Commit ea986b3

Browse files
committed
Add location attributes field to backup model
The new location attributes field exposes attributes which can be different per location. This is mainly to enable encrypted/unencrypted backups per location, but we also expose size as an encrypted backup can be slightly different (a couple of bytes larger) in size.
1 parent f910029 commit ea986b3

10 files changed

+182
-0
lines changed

aiohasupervisor/models/backups.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ class BackupContent(ResponseData):
4545
folders: list[Folder]
4646

4747

48+
@dataclass(frozen=True)
49+
class BackupLocationAttributes(ABC):
50+
"""BackupLocationAttributes model."""
51+
52+
protected: bool
53+
size_bytes: int
54+
55+
4856
@dataclass(frozen=True)
4957
class BackupBaseFields(ABC):
5058
"""BackupBaseFields ABC type."""
@@ -58,6 +66,7 @@ class BackupBaseFields(ABC):
5866
location: str | None
5967
locations: set[str | None]
6068
protected: bool
69+
location_attributes: dict[str, BackupLocationAttributes]
6170
compressed: bool
6271

6372

tests/fixtures/backup_info.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
"size_bytes": 10123,
1010
"compressed": true,
1111
"protected": false,
12+
"location_attributes": {
13+
".local": {
14+
"protected": false,
15+
"size_bytes": 10123
16+
}
17+
},
1218
"supervisor_version": "2024.05.0",
1319
"homeassistant": null,
1420
"location": null,
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"result": "ok",
3+
"data": {
4+
"slug": "d9c48f8b",
5+
"type": "partial",
6+
"name": "test_consolidate",
7+
"date": "2025-01-22T18:09:28.196333+00:00",
8+
"size": 0.01,
9+
"size_bytes": 10240,
10+
"compressed": true,
11+
"protected": true,
12+
"location_attributes": {
13+
".local": {
14+
"protected": true,
15+
"size_bytes": 10240
16+
},
17+
"test": {
18+
"protected": true,
19+
"size_bytes": 10240
20+
}
21+
},
22+
"supervisor_version": "2025.01.1.dev2104",
23+
"homeassistant": null,
24+
"location": null,
25+
"locations": [null, "test"],
26+
"addons": [],
27+
"repositories": [
28+
"https://github.com/esphome/home-assistant-addon",
29+
"https://github.com/hassio-addons/repository",
30+
"https://github.com/music-assistant/home-assistant-addon",
31+
"local",
32+
"core"
33+
],
34+
"folders": ["ssl"],
35+
"homeassistant_exclude_database": null,
36+
"extra": {}
37+
}
38+
}

tests/fixtures/backup_info_no_homeassistant.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
"size_bytes": 120123,
1010
"compressed": true,
1111
"protected": false,
12+
"location_attributes": {
13+
".local": {
14+
"protected": false,
15+
"size_bytes": 120123
16+
}
17+
},
1218
"supervisor_version": "2023.08.2.dev1002",
1319
"homeassistant": null,
1420
"location": "Test",

tests/fixtures/backup_info_with_extra.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
"size_bytes": 10123,
1010
"compressed": true,
1111
"protected": false,
12+
"location_attributes": {
13+
".local": {
14+
"protected": false,
15+
"size_bytes": 10123
16+
}
17+
},
1218
"supervisor_version": "2024.05.0",
1319
"homeassistant": null,
1420
"location": null,

tests/fixtures/backup_info_with_locations.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99
"size_bytes": 10123,
1010
"compressed": true,
1111
"protected": false,
12+
"location_attributes": {
13+
".local": {
14+
"protected": false,
15+
"size_bytes": 10123
16+
},
17+
"Test": {
18+
"protected": false,
19+
"size_bytes": 10123
20+
}
21+
},
1222
"supervisor_version": "2024.05.0",
1323
"homeassistant": null,
1424
"location": null,

tests/fixtures/backups_info.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
"location": null,
1313
"locations": [null],
1414
"protected": false,
15+
"location_attributes": {
16+
".local": {
17+
"protected": false,
18+
"size_bytes": 828810000
19+
}
20+
},
1521
"compressed": true,
1622
"content": {
1723
"homeassistant": true,
@@ -38,6 +44,12 @@
3844
"location": null,
3945
"locations": [null],
4046
"protected": false,
47+
"location_attributes": {
48+
".local": {
49+
"protected": false,
50+
"size_bytes": 120123
51+
}
52+
},
4153
"compressed": true,
4254
"content": {
4355
"homeassistant": false,

tests/fixtures/backups_list.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
"location": null,
1313
"locations": [null],
1414
"protected": false,
15+
"location_attributes": {
16+
".local": {
17+
"protected": false,
18+
"size_bytes": 828810000
19+
}
20+
},
1521
"compressed": true,
1622
"content": {
1723
"homeassistant": true,
@@ -38,6 +44,12 @@
3844
"location": null,
3945
"locations": [null],
4046
"protected": false,
47+
"location_attributes": {
48+
".local": {
49+
"protected": false,
50+
"size_bytes": 10123
51+
}
52+
},
4153
"compressed": true,
4254
"content": {
4355
"homeassistant": false,
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"result": "ok",
3+
"data": {
4+
"backups": [
5+
{
6+
"slug": "d9c48f8b",
7+
"name": "test_consolidate",
8+
"date": "2025-01-22T18:09:28.196333+00:00",
9+
"type": "partial",
10+
"size": 0.01,
11+
"size_bytes": 10240,
12+
"location": null,
13+
"locations": [null, "test"],
14+
"protected": true,
15+
"location_attributes": {
16+
".local": {
17+
"protected": true,
18+
"size_bytes": 10240
19+
},
20+
"test": {
21+
"protected": true,
22+
"size_bytes": 10240
23+
}
24+
},
25+
"compressed": true,
26+
"content": {
27+
"homeassistant": false,
28+
"addons": [],
29+
"folders": ["ssl"]
30+
}
31+
}
32+
]
33+
}
34+
}

tests/test_backups.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
RemoveBackupOptions,
2525
UploadBackupOptions,
2626
)
27+
from aiohasupervisor.models.backups import BackupLocationAttributes
2728

2829
from . import load_fixture
2930
from .const import SUPERVISOR_URL
@@ -571,3 +572,51 @@ async def test_full_backup_model(
571572
"""Test full backup model parsing and serializing."""
572573
assert FullBackupOptions.from_dict(as_dict) == options
573574
assert options.to_dict() == as_dict
575+
576+
577+
async def test_backups_list_location_attributes(
578+
responses: aioresponses,
579+
supervisor_client: SupervisorClient,
580+
) -> None:
581+
"""Test location attributes field in backups list."""
582+
responses.get(
583+
f"{SUPERVISOR_URL}/backups",
584+
status=200,
585+
body=load_fixture("backups_list_location_attributes.json"),
586+
)
587+
588+
result = await supervisor_client.backups.list()
589+
assert result[0].location_attributes == {
590+
".local": BackupLocationAttributes(
591+
protected=True,
592+
size_bytes=10240,
593+
),
594+
"test": BackupLocationAttributes(
595+
protected=True,
596+
size_bytes=10240,
597+
),
598+
}
599+
600+
601+
async def test_backup_info_location_attributes(
602+
responses: aioresponses,
603+
supervisor_client: SupervisorClient,
604+
) -> None:
605+
"""Test location attributes field in backup info."""
606+
responses.get(
607+
f"{SUPERVISOR_URL}/backups/d9c48f8b/info",
608+
status=200,
609+
body=load_fixture("backup_info_location_attributes.json"),
610+
)
611+
612+
result = await supervisor_client.backups.backup_info("d9c48f8b")
613+
assert result.location_attributes == {
614+
".local": BackupLocationAttributes(
615+
protected=True,
616+
size_bytes=10240,
617+
),
618+
"test": BackupLocationAttributes(
619+
protected=True,
620+
size_bytes=10240,
621+
),
622+
}

0 commit comments

Comments
 (0)