Skip to content

Commit f708aa8

Browse files
committed
Add host.get_disk_usage to support the new API
1 parent 1df8c34 commit f708aa8

File tree

4 files changed

+214
-0
lines changed

4 files changed

+214
-0
lines changed

aiohasupervisor/host.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from .client import _SupervisorComponentClient
44
from .const import TIMEOUT_60_SECONDS
55
from .models.host import (
6+
DiskUsage,
67
HostInfo,
78
HostOptions,
89
RebootOptions,
@@ -47,4 +48,12 @@ async def services(self) -> list[Service]:
4748
result = await self._client.get("host/services")
4849
return ServiceList.from_dict(result.data).services
4950

51+
async def get_disk_usage(self, max_depth: int = 1) -> DiskUsage:
52+
"""Get disk usage."""
53+
result = await self._client.get(
54+
"host/disk/default/usage",
55+
params={"max_depth": str(max_depth)},
56+
)
57+
return DiskUsage.from_dict(result.data)
58+
5059
# Omitted for now - Log endpoints

aiohasupervisor/models/host.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,12 @@ class ServiceList(ResponseData):
9696
"""ServiceList model."""
9797

9898
services: list[Service]
99+
100+
101+
@dataclass(frozen=True, slots=True)
102+
class DiskUsage(ResponseData):
103+
"""DiskUsage model."""
104+
105+
total_space: int | None
106+
used_space: int
107+
children: dict[str, "DiskUsage"] | None
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
{
2+
"result": "ok",
3+
"data": {
4+
"total_space": 503312781312,
5+
"used_space": 430243422208,
6+
"children": {
7+
"addons_data": {
8+
"total_space": null,
9+
"used_space": 42347618720,
10+
"children": {
11+
"77f1785d_remote_api": {
12+
"total_space": null,
13+
"used_space": 2,
14+
"children": null
15+
},
16+
"core_samba": {
17+
"total_space": null,
18+
"used_space": 517,
19+
"children": null
20+
},
21+
"a0d7b954_plex": {
22+
"total_space": null,
23+
"used_space": 757750613,
24+
"children": null
25+
},
26+
"core_whisper": {
27+
"total_space": null,
28+
"used_space": 560933406,
29+
"children": null
30+
}
31+
}
32+
},
33+
"addons_config": {
34+
"total_space": null,
35+
"used_space": 5283318814,
36+
"children": {
37+
"core_zwave_js": {
38+
"total_space": null,
39+
"used_space": 258064,
40+
"children": null
41+
},
42+
"db21ed7f_qbittorrent": {
43+
"total_space": null,
44+
"used_space": 9508283,
45+
"children": null
46+
}
47+
}
48+
},
49+
"media": {
50+
"total_space": null,
51+
"used_space": 476680019,
52+
"children": {
53+
"jellyfin": {
54+
"total_space": null,
55+
"used_space": 409122725,
56+
"children": null
57+
}
58+
}
59+
},
60+
"share": {
61+
"total_space": null,
62+
"used_space": 37477206419,
63+
"children": {
64+
"supervisor": {
65+
"total_space": null,
66+
"used_space": 929143825,
67+
"children": null
68+
},
69+
"openwakeword": {
70+
"total_space": null,
71+
"used_space": 2263836,
72+
"children": null
73+
}
74+
}
75+
},
76+
"backup": {
77+
"total_space": null,
78+
"used_space": 268350699520,
79+
"children": null
80+
},
81+
"ssl": {
82+
"total_space": null,
83+
"used_space": 202912633,
84+
"children": {
85+
"nginxproxymanager": {
86+
"total_space": null,
87+
"used_space": 202879859,
88+
"children": null
89+
},
90+
"openvpn_server": {
91+
"total_space": null,
92+
"used_space": 27500,
93+
"children": null
94+
}
95+
}
96+
},
97+
"homeassistant": {
98+
"total_space": null,
99+
"used_space": 444089236,
100+
"children": {
101+
"image": {
102+
"total_space": null,
103+
"used_space": 571875,
104+
"children": null
105+
},
106+
"custom_components": {
107+
"total_space": null,
108+
"used_space": 58343146,
109+
"children": null
110+
},
111+
"www": {
112+
"total_space": null,
113+
"used_space": 70562846,
114+
"children": null
115+
}
116+
}
117+
},
118+
"system": {
119+
"total_space": null,
120+
"used_space": 75660896847,
121+
"children": null
122+
}
123+
}
124+
}
125+
}

tests/test_host.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,74 @@ async def test_host_services(
111111
assert result[-1].name == "systemd-resolved.service"
112112
assert result[-1].description == "Network Name Resolution"
113113
assert result[-1].state == "active"
114+
115+
116+
async def test_host_disk_usage(
117+
responses: aioresponses, supervisor_client: SupervisorClient
118+
) -> None:
119+
"""Test host disk usage API."""
120+
responses.get(
121+
f"{SUPERVISOR_URL}/host/disk/default/usage?max_depth=1",
122+
status=200,
123+
body=load_fixture("host_disk_usage.json"),
124+
)
125+
result = await supervisor_client.host.get_disk_usage()
126+
127+
# Test top-level properties
128+
assert result.total_space == 503312781312
129+
assert result.used_space == 430243422208
130+
assert result.children is not None
131+
132+
# Test children structure
133+
children = result.children
134+
assert "addons_data" in children
135+
assert "addons_config" in children
136+
assert "media" in children
137+
assert "share" in children
138+
assert "backup" in children
139+
assert "ssl" in children
140+
assert "homeassistant" in children
141+
assert "system" in children
142+
143+
# Test nested children (recursive structure)
144+
addons_data = children["addons_data"]
145+
assert addons_data.used_space == 42347618720
146+
assert addons_data.children is not None
147+
assert "77f1785d_remote_api" in addons_data.children
148+
assert "core_samba" in addons_data.children
149+
assert "a0d7b954_plex" in addons_data.children
150+
assert "core_whisper" in addons_data.children
151+
152+
# Test deeper nesting
153+
plex_addon = addons_data.children["a0d7b954_plex"]
154+
assert plex_addon.used_space == 757750613
155+
assert plex_addon.children is None # Leaf node
156+
157+
# Test another branch
158+
homeassistant = children["homeassistant"]
159+
assert homeassistant.used_space == 444089236
160+
assert homeassistant.children is not None
161+
assert "image" in homeassistant.children
162+
assert "custom_components" in homeassistant.children
163+
assert "www" in homeassistant.children
164+
165+
# Test leaf node without children
166+
backup = children["backup"]
167+
assert backup.used_space == 268350699520
168+
assert backup.children is None
169+
170+
171+
async def test_host_disk_usage_with_custom_depth(
172+
responses: aioresponses, supervisor_client: SupervisorClient
173+
) -> None:
174+
"""Test host disk usage API with custom max_depth."""
175+
responses.get(
176+
f"{SUPERVISOR_URL}/host/disk/default/usage?max_depth=3",
177+
status=200,
178+
body=load_fixture("host_disk_usage.json"),
179+
)
180+
result = await supervisor_client.host.get_disk_usage(max_depth=3)
181+
182+
# Test that the custom max_depth parameter was used
183+
assert result.total_space == 503312781312
184+
assert result.used_space == 430243422208

0 commit comments

Comments
 (0)