Skip to content

Add location attributes field to backup model #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions aiohasupervisor/models/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ class BackupContent(ResponseData):
folders: list[Folder]


@dataclass(frozen=True)
class BackupLocationAttributes(ABC):
"""BackupLocationAttributes model."""

protected: bool
size_bytes: int


@dataclass(frozen=True)
class BackupBaseFields(ABC):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a follow-up PR, I think we should remove the deprecated fields from this and other backup related types.
We can't easily change the supervisor HTTP API, but we don't need to include the extra data here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, we can remove it in the client library.

"""BackupBaseFields ABC type."""
Expand All @@ -58,6 +66,7 @@ class BackupBaseFields(ABC):
location: str | None
locations: set[str | None]
protected: bool
location_attributes: dict[str, BackupLocationAttributes]
compressed: bool


Expand Down
6 changes: 6 additions & 0 deletions tests/fixtures/backup_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
"size_bytes": 10123,
"compressed": true,
"protected": false,
"location_attributes": {
".local": {
"protected": false,
"size_bytes": 10123
}
},
"supervisor_version": "2024.05.0",
"homeassistant": null,
"location": null,
Expand Down
38 changes: 38 additions & 0 deletions tests/fixtures/backup_info_location_attributes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"result": "ok",
"data": {
"slug": "d9c48f8b",
"type": "partial",
"name": "test_consolidate",
"date": "2025-01-22T18:09:28.196333+00:00",
"size": 0.01,
"size_bytes": 10240,
"compressed": true,
"protected": true,
"location_attributes": {
".local": {
"protected": true,
"size_bytes": 10240
},
"test": {
"protected": true,
"size_bytes": 10240
}
},
"supervisor_version": "2025.01.1.dev2104",
"homeassistant": null,
"location": null,
"locations": [null, "test"],
"addons": [],
"repositories": [
"https://github.com/esphome/home-assistant-addon",
"https://github.com/hassio-addons/repository",
"https://github.com/music-assistant/home-assistant-addon",
"local",
"core"
],
"folders": ["ssl"],
"homeassistant_exclude_database": null,
"extra": {}
}
}
6 changes: 6 additions & 0 deletions tests/fixtures/backup_info_no_homeassistant.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
"size_bytes": 120123,
"compressed": true,
"protected": false,
"location_attributes": {
".local": {
"protected": false,
"size_bytes": 120123
}
},
"supervisor_version": "2023.08.2.dev1002",
"homeassistant": null,
"location": "Test",
Expand Down
6 changes: 6 additions & 0 deletions tests/fixtures/backup_info_with_extra.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
"size_bytes": 10123,
"compressed": true,
"protected": false,
"location_attributes": {
".local": {
"protected": false,
"size_bytes": 10123
}
},
"supervisor_version": "2024.05.0",
"homeassistant": null,
"location": null,
Expand Down
10 changes: 10 additions & 0 deletions tests/fixtures/backup_info_with_locations.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
"size_bytes": 10123,
"compressed": true,
"protected": false,
"location_attributes": {
".local": {
"protected": false,
"size_bytes": 10123
},
"Test": {
"protected": false,
"size_bytes": 10123
}
},
"supervisor_version": "2024.05.0",
"homeassistant": null,
"location": null,
Expand Down
12 changes: 12 additions & 0 deletions tests/fixtures/backups_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
"location": null,
"locations": [null],
"protected": false,
"location_attributes": {
".local": {
"protected": false,
"size_bytes": 828810000
}
},
"compressed": true,
"content": {
"homeassistant": true,
Expand All @@ -38,6 +44,12 @@
"location": null,
"locations": [null],
"protected": false,
"location_attributes": {
".local": {
"protected": false,
"size_bytes": 120123
}
},
"compressed": true,
"content": {
"homeassistant": false,
Expand Down
12 changes: 12 additions & 0 deletions tests/fixtures/backups_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
"location": null,
"locations": [null],
"protected": false,
"location_attributes": {
".local": {
"protected": false,
"size_bytes": 828810000
}
},
"compressed": true,
"content": {
"homeassistant": true,
Expand All @@ -38,6 +44,12 @@
"location": null,
"locations": [null],
"protected": false,
"location_attributes": {
".local": {
"protected": false,
"size_bytes": 10123
}
},
"compressed": true,
"content": {
"homeassistant": false,
Expand Down
34 changes: 34 additions & 0 deletions tests/fixtures/backups_list_location_attributes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"result": "ok",
"data": {
"backups": [
{
"slug": "d9c48f8b",
"name": "test_consolidate",
"date": "2025-01-22T18:09:28.196333+00:00",
"type": "partial",
"size": 0.01,
"size_bytes": 10240,
"location": null,
"locations": [null, "test"],
"protected": true,
"location_attributes": {
".local": {
"protected": true,
"size_bytes": 10240
},
"test": {
"protected": true,
"size_bytes": 10240
}
},
"compressed": true,
"content": {
"homeassistant": false,
"addons": [],
"folders": ["ssl"]
}
}
]
}
}
49 changes: 49 additions & 0 deletions tests/test_backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
RemoveBackupOptions,
UploadBackupOptions,
)
from aiohasupervisor.models.backups import BackupLocationAttributes

from . import load_fixture
from .const import SUPERVISOR_URL
Expand Down Expand Up @@ -571,3 +572,51 @@ async def test_full_backup_model(
"""Test full backup model parsing and serializing."""
assert FullBackupOptions.from_dict(as_dict) == options
assert options.to_dict() == as_dict


async def test_backups_list_location_attributes(
responses: aioresponses,
supervisor_client: SupervisorClient,
) -> None:
"""Test location attributes field in backups list."""
responses.get(
f"{SUPERVISOR_URL}/backups",
status=200,
body=load_fixture("backups_list_location_attributes.json"),
)

result = await supervisor_client.backups.list()
assert result[0].location_attributes == {
".local": BackupLocationAttributes(
protected=True,
size_bytes=10240,
),
"test": BackupLocationAttributes(
protected=True,
size_bytes=10240,
),
}


async def test_backup_info_location_attributes(
responses: aioresponses,
supervisor_client: SupervisorClient,
) -> None:
"""Test location attributes field in backup info."""
responses.get(
f"{SUPERVISOR_URL}/backups/d9c48f8b/info",
status=200,
body=load_fixture("backup_info_location_attributes.json"),
)

result = await supervisor_client.backups.backup_info("d9c48f8b")
assert result.location_attributes == {
".local": BackupLocationAttributes(
protected=True,
size_bytes=10240,
),
"test": BackupLocationAttributes(
protected=True,
size_bytes=10240,
),
}
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy