Files
Christian Manivong ed8e58267a
driver / lint (pull_request) Successful in 15s
driver / standard (pull_request) Successful in 19s
driver / lowest (pull_request) Failing after 25s
driver / types (pull_request) Successful in 1m5s
driver / test (3.12) (pull_request) Successful in 1m11s
driver / test (3.13) (pull_request) Successful in 1m3s
driver / build (pull_request) Successful in 30s
driver / security (pull_request) Successful in 1m8s
CI / driver (pull_request) Failing after 1m52s
driver / publish (pull_request) Skipped
feat: Home Assistant OS driver over the WebSocket API (0.1.0)
A driver for Home Assistant OS and Supervised installs. It reaches the
Supervisor through Home Assistant's WebSocket (supervisor/api) with an
administrator's long-lived access token: no add-on, no SSH.

Getters: facts, interfaces and addresses, host status (pending reboot,
data disk), pending updates of Core, OS, Supervisor and add-ons, add-ons
as services, running backups. Actions: apply updates, add-on start/stop/
restart and start at boot, refresh updates, reboot and shutdown.

The fixtures are built from the Supervisor 2026.11.0 API source, not
recorded; they are replaced once the first device is onboarded.
2026-12-03 01:22:18 +01:00

310 lines
8.9 KiB
Python

"""The parsers: Supervisor answers in, the contract's dicts out."""
from __future__ import annotations
from napalm_homeassistant.parsers import (
board_model,
parse_facts,
parse_host_status,
parse_interfaces,
parse_interfaces_ip,
parse_running_backups,
parse_services,
parse_updates,
uptime_seconds,
)
from tests.conftest import load
GIB = 1024**3
# --- facts -------------------------------------------------------------------------------
def test_facts_of_a_home_assistant_os_vm() -> None:
facts = parse_facts(load("host-info"), load("os-info"), load("network-info"))
assert facts == {
"vendor": "Home Assistant",
"model": "Virtual Machine",
"hostname": "ha-lab-01",
"fqdn": "ha-lab-01",
"os_version": "Home Assistant OS 18.4",
"serial_number": "",
"uptime": 1_728_000.0,
"interface_list": ["enp6s18", "wlan0"],
}
def test_facts_of_a_supervised_install_name_no_board() -> None:
os_info = load("os-info")
os_info["board"] = None
host = load("host-info")
host["operating_system"] = "Debian GNU/Linux 13 (trixie)"
facts = parse_facts(host, os_info, load("network-info"))
assert facts["model"] == "Home Assistant Supervised"
assert facts["os_version"] == "Debian GNU/Linux 13 (trixie)"
def test_known_boards_have_their_product_names() -> None:
assert board_model("green") == "Home Assistant Green"
assert board_model("yellow") == "Home Assistant Yellow"
assert board_model("rpi5-64") == "Raspberry Pi 5"
assert board_model("generic-x86-64") == "Generic x86-64"
def test_an_unknown_board_is_named_as_the_supervisor_names_it() -> None:
assert board_model("odroid-m1s") == "odroid-m1s"
def test_uptime_is_unknown_without_a_boot_timestamp() -> None:
host = load("host-info")
host["boot_timestamp"] = None
assert uptime_seconds(host) == -1.0
def test_uptime_is_unknown_without_the_host_clock() -> None:
host = load("host-info")
del host["dt_utc"]
assert uptime_seconds(host) == -1.0
# --- interfaces --------------------------------------------------------------------------
def test_interfaces() -> None:
interfaces = parse_interfaces(load("network-info"))
assert interfaces["enp6s18"] == {
"is_up": True,
"is_enabled": True,
"description": "",
"last_flapped": -1.0,
"speed": -1.0,
"mtu": -1,
"mac_address": "02:00:5E:10:00:21",
}
assert interfaces["wlan0"]["is_up"] is False
assert interfaces["wlan0"]["is_enabled"] is False
def test_interface_addresses() -> None:
addresses = parse_interfaces_ip(load("network-info"))
assert addresses == {
"enp6s18": {
"ipv4": {"192.0.2.21": {"prefix_length": 24}},
"ipv6": {
"2001:db8::21": {"prefix_length": 64},
"fe80::5dbe:d5ae:4e3f:77bc": {"prefix_length": 64},
},
}
}
def test_an_interface_without_addresses_is_left_out() -> None:
network = load("network-info")
network["interfaces"][0]["ipv4"]["address"] = []
network["interfaces"][0]["ipv6"] = None
assert parse_interfaces_ip(network) == {}
# --- updates -----------------------------------------------------------------------------
def test_pending_updates_of_os_core_and_add_ons() -> None:
updates = parse_updates(
load("core-info"), load("os-info"), load("supervisor-info"), load("addons")
)
assert updates == [
{
"name": "core",
"current_version": "2026.11.3",
"new_version": "2026.12.0",
"origin": "stable",
"title": "Home Assistant Core",
},
{
"name": "os",
"current_version": "18.4",
"new_version": "18.5",
"origin": "stable",
"title": "Home Assistant OS",
},
{
"name": "a0d7b954_vscode",
"current_version": "7.2.0",
"new_version": "7.3.0",
"origin": "a0d7b954",
"title": "Studio Code Server",
},
]
def test_a_supervisor_update_is_listed() -> None:
supervisor = load("supervisor-info")
supervisor.update(update_available=True, version_latest="2026.12.0")
updates = parse_updates(load("core-info"), load("os-info"), supervisor, {"addons": []})
assert {
"name": "supervisor",
"current_version": "2026.11.0",
"new_version": "2026.12.0",
"origin": "stable",
"title": "Home Assistant Supervisor",
} in updates
def test_nothing_pending_is_an_empty_list() -> None:
core = load("core-info")
core["update_available"] = False
os_info = load("os-info")
os_info["update_available"] = False
assert parse_updates(core, os_info, load("supervisor-info"), {"addons": []}) == []
def test_a_supervised_install_has_no_os_update() -> None:
os_info = load("os-info")
os_info.update(version=None, version_latest=None, update_available=False, board=None)
core = load("core-info")
core["update_available"] = False
assert parse_updates(core, os_info, load("supervisor-info"), {"addons": []}) == []
# --- host status -------------------------------------------------------------------------
def test_host_status_with_nothing_pending() -> None:
status = parse_host_status(load("host-info"), load("os-info"), load("resolution-info"))
assert status == {
"reboot_required": False,
"reboot_reason": None,
"auto_updates": None,
"package_manager": None,
"filesystems": [
{
"mountpoint": "/mnt/data",
"total": int(30.8 * GIB),
"used": int(12.3 * GIB),
"available": int(17.1 * GIB),
}
],
}
def test_an_installed_os_waiting_for_the_reboot_names_both_versions() -> None:
os_info = load("os-info")
os_info["version_pending"] = "18.5"
status = parse_host_status(load("host-info"), os_info, load("resolution-info"))
assert status["reboot_required"] is True
assert status["reboot_reason"] == "Home Assistant OS 18.5 installed, 18.4 running"
def test_the_supervisors_reboot_issue_requires_a_reboot() -> None:
resolution = load("resolution-info")
resolution["issues"].append(
{"uuid": "ab", "type": "reboot_required", "context": "system", "reference": None}
)
status = parse_host_status(load("host-info"), load("os-info"), resolution)
assert status["reboot_required"] is True
assert status["reboot_reason"] == "the Supervisor reports a reboot required"
def test_disk_figures_missing_leave_the_filesystems_unread() -> None:
host = load("host-info")
host["disk_total"] = None
status = parse_host_status(host, load("os-info"), load("resolution-info"))
assert status["filesystems"] is None
# --- add-ons -----------------------------------------------------------------------------
def test_add_ons_as_services() -> None:
services = parse_services(load("addons"), load("addon-boot"))
assert services == [
{"name": "core_mosquitto", "running": True, "enabled": True, "pid": 0, "result": "success"},
{"name": "core_samba", "running": True, "enabled": True, "pid": 0, "result": "success"},
{
"name": "a0d7b954_vscode",
"running": False,
"enabled": False,
"pid": 0,
"result": "success",
},
{
"name": "a0d7b954_ssh",
"running": False,
"enabled": True,
"pid": 0,
"result": "exit-code",
},
]
def test_an_add_on_in_an_unknown_state_has_no_result() -> None:
addons = load("addons")
addons["addons"][0]["state"] = "unknown"
assert parse_services(addons, load("addon-boot"))[0]["result"] is None
def test_an_add_on_without_its_boot_setting_is_not_enabled() -> None:
services = parse_services(load("addons"), {})
assert [s["enabled"] for s in services] == [False, False, False, False]
# --- running backups ---------------------------------------------------------------------
def test_a_backup_in_progress_is_running() -> None:
assert parse_running_backups(load("jobs-info")) == [
{
"kind": "backup",
"job": None,
"task": "0a1b2c3d4e5f60718293a4b5c6d7e8f9",
"guests": [],
"since": 1_796_284_500,
}
]
def test_a_backup_nested_under_another_job_is_found() -> None:
jobs = load("jobs-info")
backup = jobs["jobs"].pop(0)
jobs["jobs"][1]["child_jobs"] = [backup]
assert [b["task"] for b in parse_running_backups(jobs)] == [backup["uuid"]]
def test_no_backup_running_is_an_empty_list() -> None:
jobs = load("jobs-info")
jobs["jobs"][0]["done"] = True
assert parse_running_backups(jobs) == []
def test_a_backup_without_a_creation_time_has_no_start() -> None:
jobs = load("jobs-info")
jobs["jobs"][0]["created"] = None
assert parse_running_backups(jobs)[0]["since"] is None