Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .client import _SupervisorComponentClient
from .const import TIMEOUT_60_SECONDS
from .models.host import (
DiskUsage,
HostInfo,
HostOptions,
RebootOptions,
Expand Down Expand Up @@ -47,4 +48,12 @@ async def services(self) -> list[Service]:
result = await self._client.get("host/services")
return ServiceList.from_dict(result.data).services

async def get_disk_usage(self, max_depth: int = 1) -> DiskUsage:
"""Get disk usage."""
result = await self._client.get(
"host/disk/default/usage",
params={"max_depth": str(max_depth)},
)
return DiskUsage.from_dict(result.data)

# Omitted for now - Log endpoints
9 changes: 9 additions & 0 deletions aiohasupervisor/models/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,12 @@ class ServiceList(ResponseData):
"""ServiceList model."""

services: list[Service]


@dataclass(frozen=True, slots=True)
class DiskUsage(ResponseData):
"""DiskUsage model."""

total_space: int | None
used_space: int
children: dict[str, "DiskUsage"] | None
125 changes: 125 additions & 0 deletions tests/fixtures/host_disk_usage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{
"result": "ok",
"data": {
"total_space": 503312781312,
"used_space": 430243422208,
"children": {
"addons_data": {
"total_space": null,
"used_space": 42347618720,
"children": {
"77f1785d_remote_api": {
"total_space": null,
"used_space": 2,
"children": null
},
"core_samba": {
"total_space": null,
"used_space": 517,
"children": null
},
"a0d7b954_plex": {
"total_space": null,
"used_space": 757750613,
"children": null
},
"core_whisper": {
"total_space": null,
"used_space": 560933406,
"children": null
}
}
},
"addons_config": {
"total_space": null,
"used_space": 5283318814,
"children": {
"core_zwave_js": {
"total_space": null,
"used_space": 258064,
"children": null
},
"db21ed7f_qbittorrent": {
"total_space": null,
"used_space": 9508283,
"children": null
}
}
},
"media": {
"total_space": null,
"used_space": 476680019,
"children": {
"jellyfin": {
"total_space": null,
"used_space": 409122725,
"children": null
}
}
},
"share": {
"total_space": null,
"used_space": 37477206419,
"children": {
"supervisor": {
"total_space": null,
"used_space": 929143825,
"children": null
},
"openwakeword": {
"total_space": null,
"used_space": 2263836,
"children": null
}
}
},
"backup": {
"total_space": null,
"used_space": 268350699520,
"children": null
},
"ssl": {
"total_space": null,
"used_space": 202912633,
"children": {
"nginxproxymanager": {
"total_space": null,
"used_space": 202879859,
"children": null
},
"openvpn_server": {
"total_space": null,
"used_space": 27500,
"children": null
}
}
},
"homeassistant": {
"total_space": null,
"used_space": 444089236,
"children": {
"image": {
"total_space": null,
"used_space": 571875,
"children": null
},
"custom_components": {
"total_space": null,
"used_space": 58343146,
"children": null
},
"www": {
"total_space": null,
"used_space": 70562846,
"children": null
}
}
},
"system": {
"total_space": null,
"used_space": 75660896847,
"children": null
}
}
}
}
71 changes: 71 additions & 0 deletions tests/test_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,74 @@ async def test_host_services(
assert result[-1].name == "systemd-resolved.service"
assert result[-1].description == "Network Name Resolution"
assert result[-1].state == "active"


async def test_host_disk_usage(
responses: aioresponses, supervisor_client: SupervisorClient
) -> None:
"""Test host disk usage API."""
responses.get(
f"{SUPERVISOR_URL}/host/disk/default/usage?max_depth=1",
status=200,
body=load_fixture("host_disk_usage.json"),
)
result = await supervisor_client.host.get_disk_usage()

# Test top-level properties
assert result.total_space == 503312781312
assert result.used_space == 430243422208
assert result.children is not None

# Test children structure
children = result.children
assert "addons_data" in children
assert "addons_config" in children
assert "media" in children
assert "share" in children
assert "backup" in children
assert "ssl" in children
assert "homeassistant" in children
assert "system" in children

# Test nested children (recursive structure)
addons_data = children["addons_data"]
assert addons_data.used_space == 42347618720
assert addons_data.children is not None
assert "77f1785d_remote_api" in addons_data.children
assert "core_samba" in addons_data.children
assert "a0d7b954_plex" in addons_data.children
assert "core_whisper" in addons_data.children

# Test deeper nesting
plex_addon = addons_data.children["a0d7b954_plex"]
assert plex_addon.used_space == 757750613
assert plex_addon.children is None # Leaf node

# Test another branch
homeassistant = children["homeassistant"]
assert homeassistant.used_space == 444089236
assert homeassistant.children is not None
assert "image" in homeassistant.children
assert "custom_components" in homeassistant.children
assert "www" in homeassistant.children

# Test leaf node without children
backup = children["backup"]
assert backup.used_space == 268350699520
assert backup.children is None


async def test_host_disk_usage_with_custom_depth(
responses: aioresponses, supervisor_client: SupervisorClient
) -> None:
"""Test host disk usage API with custom max_depth."""
responses.get(
f"{SUPERVISOR_URL}/host/disk/default/usage?max_depth=3",
status=200,
body=load_fixture("host_disk_usage.json"),
)
result = await supervisor_client.host.get_disk_usage(max_depth=3)

# Test that the custom max_depth parameter was used
assert result.total_space == 503312781312
assert result.used_space == 430243422208
Loading