@@ -111,3 +111,94 @@ 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/disks/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_bytes == 503312781312
129+ assert result .used_bytes == 430243422208
130+ assert result .children is not None
131+
132+ # Test children structure
133+ children = result .children
134+ assert children is not None
135+ assert len (children ) == 8 # Should have 8 children
136+
137+ # Find specific children by id
138+ assert (
139+ addons_data := next (child for child in children if child .id == "addons_data" )
140+ )
141+ assert next (child for child in children if child .id == "addons_config" )
142+ assert next (child for child in children if child .id == "media" )
143+ assert next (child for child in children if child .id == "share" )
144+ assert (backup := next (child for child in children if child .id == "backup" ))
145+ assert next (child for child in children if child .id == "ssl" )
146+ assert (
147+ homeassistant := next (
148+ child for child in children if child .id == "homeassistant"
149+ )
150+ )
151+ assert next (child for child in children if child .id == "system" )
152+
153+ # Test nested children (recursive structure)
154+ assert addons_data .used_bytes == 42347618720
155+ assert addons_data .children is not None
156+ assert len (addons_data .children ) == 4
157+
158+ # Find specific nested children
159+ assert next (
160+ child for child in addons_data .children if child .id == "77f1785d_remote_api"
161+ )
162+ assert next (child for child in addons_data .children if child .id == "core_samba" )
163+ assert (
164+ plex_addon := next (
165+ child for child in addons_data .children if child .id == "a0d7b954_plex"
166+ )
167+ )
168+ assert next (child for child in addons_data .children if child .id == "core_whisper" )
169+
170+ # Test deeper nesting
171+ assert plex_addon .used_bytes == 757750613
172+ assert plex_addon .children is None # Leaf node
173+
174+ # Test another branch
175+ assert homeassistant .used_bytes == 444089236
176+ assert homeassistant .children is not None
177+ assert len (homeassistant .children ) == 3
178+
179+ # Find specific homeassistant children
180+ assert next (child for child in homeassistant .children if child .id == "image" )
181+ assert next (
182+ child for child in homeassistant .children if child .id == "custom_components"
183+ )
184+ assert next (child for child in homeassistant .children if child .id == "www" )
185+
186+ # Test leaf node without children
187+ assert backup .used_bytes == 268350699520
188+ assert backup .children is None
189+
190+
191+ async def test_host_disk_usage_with_custom_depth (
192+ responses : aioresponses , supervisor_client : SupervisorClient
193+ ) -> None :
194+ """Test host disk usage API with custom max_depth."""
195+ responses .get (
196+ f"{ SUPERVISOR_URL } /host/disks/default/usage?max_depth=3" ,
197+ status = 200 ,
198+ body = load_fixture ("host_disk_usage.json" ),
199+ )
200+ result = await supervisor_client .host .get_disk_usage (max_depth = 3 )
201+
202+ # Test that the custom max_depth parameter was used
203+ assert result .total_bytes == 503312781312
204+ assert result .used_bytes == 430243422208
0 commit comments