Skip to content

Commit 8ec3d06

Browse files
committed
Add model changes
1 parent d45b3d8 commit 8ec3d06

File tree

9 files changed

+195
-14
lines changed

9 files changed

+195
-14
lines changed

aiohasupervisor/models/backups.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ class BackupBaseFields(ABC):
4747
date: datetime
4848
type: BackupType
4949
size: float
50+
size_bytes: int
5051
location: str | None
52+
locations: set[str | None]
5153
protected: bool
5254
compressed: bool
5355

@@ -79,6 +81,7 @@ class BackupComplete(BackupBaseFields, ResponseData):
7981
repositories: list[str]
8082
folders: list[Folder]
8183
homeassistant_exclude_database: bool | None
84+
extra: dict | None
8285

8386

8487
@dataclass(frozen=True, slots=True)
@@ -132,7 +135,7 @@ class FullBackupOptions(Request):
132135
name: str | None = None
133136
password: str | None = None
134137
compressed: bool | None = None
135-
location: list[str | None] | str | None = None
138+
location: set[str | None] | str | None = None
136139
homeassistant_exclude_database: bool | None = None
137140
background: bool | None = None
138141
extra: dict | None = None

aiohasupervisor/models/mounts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class MountResponse(ABC):
7979
name: str
8080
read_only: bool
8181
state: MountState | None
82+
user_path: PurePath | None
8283

8384

8485
@dataclass(frozen=True)

tests/fixtures/backup_info.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
"name": "addon_core_mosquitto_6.4.0",
77
"date": "2024-05-31T00:00:00.000000+00:00",
88
"size": 0.01,
9+
"size_bytes": 10123,
910
"compressed": true,
1011
"protected": false,
1112
"supervisor_version": "2024.05.0",
1213
"homeassistant": null,
1314
"location": null,
15+
"locations": [null],
1416
"addons": [
1517
{
1618
"slug": "core_mosquitto",
@@ -27,6 +29,7 @@
2729
"https://github.com/hassio-addons/repository"
2830
],
2931
"folders": [],
30-
"homeassistant_exclude_database": null
32+
"homeassistant_exclude_database": null,
33+
"extra": null
3134
}
3235
}

tests/fixtures/backup_info_no_homeassistant.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
"name": "Studio Code Server",
77
"date": "2023-08-10T19:37:01.084215+00:00",
88
"size": 0.12,
9+
"size_bytes": 120123,
910
"compressed": true,
1011
"protected": false,
1112
"supervisor_version": "2023.08.2.dev1002",
1213
"homeassistant": null,
1314
"location": "Test",
15+
"locations": ["Test"],
1416
"addons": [
1517
{
1618
"slug": "a0d7b954_vscode",
@@ -27,6 +29,7 @@
2729
"https://github.com/esphome/home-assistant-addon"
2830
],
2931
"folders": [],
30-
"homeassistant_exclude_database": null
32+
"homeassistant_exclude_database": null,
33+
"extra": null
3134
}
3235
}
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": "69558789",
5+
"type": "partial",
6+
"name": "addon_core_mosquitto_6.4.0",
7+
"date": "2024-05-31T00:00:00.000000+00:00",
8+
"size": 0.01,
9+
"size_bytes": 10123,
10+
"compressed": true,
11+
"protected": false,
12+
"supervisor_version": "2024.05.0",
13+
"homeassistant": null,
14+
"location": null,
15+
"locations": [null],
16+
"addons": [
17+
{
18+
"slug": "core_mosquitto",
19+
"name": "Mosquitto broker",
20+
"version": "6.4.0",
21+
"size": 0.0
22+
}
23+
],
24+
"repositories": [
25+
"core",
26+
"local",
27+
"https://github.com/music-assistant/home-assistant-addon",
28+
"https://github.com/esphome/home-assistant-addon",
29+
"https://github.com/hassio-addons/repository"
30+
],
31+
"folders": [],
32+
"homeassistant_exclude_database": null,
33+
"extra": {
34+
"user": "test",
35+
"scheduled": true
36+
}
37+
}
38+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"result": "ok",
3+
"data": {
4+
"slug": "69558789",
5+
"type": "partial",
6+
"name": "addon_core_mosquitto_6.4.0",
7+
"date": "2024-05-31T00:00:00.000000+00:00",
8+
"size": 0.01,
9+
"size_bytes": 10123,
10+
"compressed": true,
11+
"protected": false,
12+
"supervisor_version": "2024.05.0",
13+
"homeassistant": null,
14+
"location": null,
15+
"locations": [null, "Test"],
16+
"addons": [
17+
{
18+
"slug": "core_mosquitto",
19+
"name": "Mosquitto broker",
20+
"version": "6.4.0",
21+
"size": 0.0
22+
}
23+
],
24+
"repositories": [
25+
"core",
26+
"local",
27+
"https://github.com/music-assistant/home-assistant-addon",
28+
"https://github.com/esphome/home-assistant-addon",
29+
"https://github.com/hassio-addons/repository"
30+
],
31+
"folders": [],
32+
"homeassistant_exclude_database": null,
33+
"extra": null
34+
}
35+
}

tests/fixtures/mounts_info.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"usage": "backup",
1212
"read_only": false,
1313
"version": null,
14-
"state": "active"
14+
"state": "active",
15+
"user_path": null
1516
},
1617
{
1718
"share": "share",
@@ -22,16 +23,18 @@
2223
"read_only": true,
2324
"version": "2.0",
2425
"port": 12345,
25-
"state": "active"
26+
"state": "active",
27+
"user_path": "/share/Test2"
2628
},
2729
{
2830
"server": "test3.local",
29-
"name": "Test2",
31+
"name": "Test3",
3032
"type": "nfs",
3133
"usage": "media",
3234
"read_only": false,
3335
"path": "media",
34-
"state": "active"
36+
"state": "active",
37+
"user_path": "/media/Test3"
3538
}
3639
]
3740
}

tests/test_backups.py

Lines changed: 99 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ async def test_partial_restore_options() -> None:
133133

134134
def backup_callback(url: str, **kwargs: dict[str, Any]) -> CallbackResult: # noqa: ARG001
135135
"""Return response based on whether backup was in background or not."""
136-
if kwargs["json"] and kwargs["json"]["background"]:
136+
if kwargs["json"] and kwargs["json"].get("background"):
137137
fixture = "backup_background.json"
138138
else:
139139
fixture = "backup_foreground.json"
@@ -145,6 +145,19 @@ def backup_callback(url: str, **kwargs: dict[str, Any]) -> CallbackResult: # no
145145
[
146146
(FullBackupOptions(name="Test", background=True), None),
147147
(FullBackupOptions(name="Test", background=False), "9ecf0028"),
148+
(FullBackupOptions(name="Test", background=False, location=None), "9ecf0028"),
149+
(FullBackupOptions(name="Test", background=False, location="test"), "9ecf0028"),
150+
(
151+
FullBackupOptions(name="Test", background=False, location={None, "test"}),
152+
"9ecf0028",
153+
),
154+
(
155+
FullBackupOptions(
156+
name="Test", background=False, extra={"user": "test", "scheduled": True}
157+
),
158+
"9ecf0028",
159+
),
160+
(FullBackupOptions(name="Test", background=False, extra=None), "9ecf0028"),
148161
(None, "9ecf0028"),
149162
],
150163
)
@@ -165,23 +178,67 @@ async def test_backups_full_backup(
165178

166179

167180
@pytest.mark.parametrize(
168-
("background", "slug"),
169-
[(True, None), (False, "9ecf0028")],
181+
("options", "slug"),
182+
[
183+
(PartialBackupOptions(name="Test", background=True, addons={"core_ssh"}), None),
184+
(
185+
PartialBackupOptions(name="Test", background=False, addons={"core_ssh"}),
186+
"9ecf0028",
187+
),
188+
(
189+
PartialBackupOptions(
190+
name="Test", background=False, location=None, addons={"core_ssh"}
191+
),
192+
"9ecf0028",
193+
),
194+
(
195+
PartialBackupOptions(
196+
name="Test", background=False, location="test", addons={"core_ssh"}
197+
),
198+
"9ecf0028",
199+
),
200+
(
201+
PartialBackupOptions(
202+
name="Test",
203+
background=False,
204+
location={None, "test"},
205+
addons={"core_ssh"},
206+
),
207+
"9ecf0028",
208+
),
209+
(
210+
PartialBackupOptions(
211+
name="Test",
212+
background=False,
213+
addons={"core_ssh"},
214+
extra={"user": "test", "scheduled": True},
215+
),
216+
"9ecf0028",
217+
),
218+
(
219+
PartialBackupOptions(
220+
name="Test", background=False, addons={"core_ssh"}, extra=None
221+
),
222+
"9ecf0028",
223+
),
224+
(
225+
PartialBackupOptions(name="Test", background=None, addons={"core_ssh"}),
226+
"9ecf0028",
227+
),
228+
],
170229
)
171230
async def test_backups_partial_backup(
172231
responses: aioresponses,
173232
supervisor_client: SupervisorClient,
174-
background: bool, # noqa: FBT001
233+
options: PartialBackupOptions,
175234
slug: str | None,
176235
) -> None:
177236
"""Test backups full backup API."""
178237
responses.post(
179238
f"{SUPERVISOR_URL}/backups/new/partial",
180239
callback=backup_callback,
181240
)
182-
result = await supervisor_client.backups.partial_backup(
183-
PartialBackupOptions(name="test", background=background, addons={"core_ssh"})
184-
)
241+
result = await supervisor_client.backups.partial_backup(options)
185242
assert result.job_id == "dc9dbc16f6ad4de592ffa72c807ca2bf"
186243
assert result.slug == slug
187244

@@ -200,6 +257,7 @@ async def test_backup_info(
200257
assert result.type == "partial"
201258
assert result.date == datetime(2024, 5, 31, 0, 0, 0, 0, UTC)
202259
assert result.size == 0.01
260+
assert result.size_bytes == 10123
203261
assert result.compressed is True
204262
assert result.addons[0].slug == "core_mosquitto"
205263
assert result.addons[0].name == "Mosquitto broker"
@@ -214,6 +272,9 @@ async def test_backup_info(
214272
]
215273
assert result.folders == []
216274
assert result.homeassistant_exclude_database is None
275+
assert result.extra is None
276+
assert result.location is None
277+
assert result.locations == {None}
217278

218279

219280
async def test_backup_info_no_homeassistant(
@@ -231,6 +292,37 @@ async def test_backup_info_no_homeassistant(
231292
assert result.homeassistant is None
232293

233294

295+
async def test_backup_info_with_extra(
296+
responses: aioresponses, supervisor_client: SupervisorClient
297+
) -> None:
298+
"""Test backup info API with extras set by client."""
299+
responses.get(
300+
f"{SUPERVISOR_URL}/backups/d13dedd0/info",
301+
status=200,
302+
body=load_fixture("backup_info_with_extra.json"),
303+
)
304+
result = await supervisor_client.backups.backup_info("d13dedd0")
305+
assert result.slug == "69558789"
306+
assert result.type == "partial"
307+
assert result.extra == {"user": "test", "scheduled": True}
308+
309+
310+
async def test_backup_info_with_multiple_locations(
311+
responses: aioresponses, supervisor_client: SupervisorClient
312+
) -> None:
313+
"""Test backup info API with multiple locations."""
314+
responses.get(
315+
f"{SUPERVISOR_URL}/backups/d13dedd0/info",
316+
status=200,
317+
body=load_fixture("backup_info_with_locations.json"),
318+
)
319+
result = await supervisor_client.backups.backup_info("d13dedd0")
320+
assert result.slug == "69558789"
321+
assert result.type == "partial"
322+
assert result.location is None
323+
assert result.locations == {None, "Test"}
324+
325+
234326
async def test_remove_backup(
235327
responses: aioresponses, supervisor_client: SupervisorClient
236328
) -> None:

tests/test_mounts.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,18 @@ async def test_mounts_info(
3737
assert info.mounts[0].read_only is False
3838
assert info.mounts[0].version is None
3939
assert info.mounts[0].state == "active"
40+
assert info.mounts[0].user_path is None
4041

4142
assert info.mounts[1].usage == "share"
4243
assert info.mounts[1].read_only is True
4344
assert info.mounts[1].version == "2.0"
4445
assert info.mounts[1].port == 12345
46+
assert info.mounts[1].user_path == PurePath("/share/Test2")
4547

4648
assert info.mounts[2].type == "nfs"
4749
assert info.mounts[2].usage == "media"
4850
assert info.mounts[2].path.as_posix() == "media"
51+
assert info.mounts[2].user_path == PurePath("/media/Test3")
4952

5053

5154
@pytest.mark.parametrize("mount_name", ["test", None])

0 commit comments

Comments
 (0)