91 lines
3.9 KiB
Python
91 lines
3.9 KiB
Python
# Copyright © 2026 Setti Solutions S.R.L, www.setti.md. All rights reserved.
|
|
"""The EEBUS add-on's manifest: what the Supervisor needs, no more rights
|
|
than EEBUS needs (the host's network, nothing else), options = schema =
|
|
translations in English and German, the image built from the bridge and
|
|
the profiles, and the public repository's rules for its files."""
|
|
import re
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
import yaml
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
ADDON = ROOT / "cantabile_eebus"
|
|
HUB_WEB = ROOT / "hub/mkosi/mkosi.extra/usr/lib/cantabile/web"
|
|
|
|
|
|
def manifest():
|
|
return yaml.safe_load((ADDON / "config.yaml").read_text())
|
|
|
|
|
|
def test_manifest():
|
|
m = manifest()
|
|
assert m["slug"] == ADDON.name and "{arch}" in m["image"] and isinstance(m["version"], str)
|
|
assert set(m["arch"]) <= {"amd64", "aarch64"}
|
|
assert "mqtt:need" in m["services"]
|
|
assert m["ingress"] is True and m["ingress_port"] == 8099 and m["panel_admin"] is True
|
|
|
|
|
|
def test_no_more_rights_than_eebus_needs():
|
|
m = manifest()
|
|
assert m["host_network"] is True # mDNS and SHIP's announced address
|
|
for k in ("privileged", "full_access", "host_pid", "docker_api", "hassio_api", "auth_api", "homeassistant_api",
|
|
"devices", "map", "ports"):
|
|
assert k not in m, k
|
|
assert m.get("hassio_role", "default") == "default"
|
|
|
|
|
|
def test_options_schema_and_translations_agree():
|
|
m = manifest()
|
|
assert set(m["options"]) <= set(m["schema"])
|
|
assert m["options"]["pass_on_limits"] is True and m["options"]["simulate"] is False
|
|
for lang in ("en", "de"):
|
|
t = yaml.safe_load((ADDON / "translations" / f"{lang}.yaml").read_text())
|
|
assert set(t["configuration"]) == set(m["schema"]), lang
|
|
for k, v in t["configuration"].items():
|
|
assert v["name"] and v["description"], (lang, k)
|
|
|
|
|
|
def test_the_bridge_reads_these_options():
|
|
main = (ROOT / "src" / "eebus-bridge" / "main.go").read_text()
|
|
for k in manifest()["schema"]:
|
|
assert f'json:"{k}"' in main, k
|
|
|
|
|
|
def test_image_and_icons():
|
|
d = (ADDON / "Dockerfile").read_text()
|
|
assert "src/eebus-bridge/*.go" in d and "src/profiles/*.json" in d and '"-ha"' in d
|
|
assert "THIRD-PARTY-NOTICES.md" in d and (ROOT / "src/eebus-bridge/THIRD-PARTY-NOTICES.md").exists()
|
|
for n in ("icon.png", "logo.png"):
|
|
assert (ADDON / n).read_bytes()[:8] == b"\x89PNG\r\n\x1a\n"
|
|
|
|
|
|
def test_public_repository_rules():
|
|
"""Setti Solutions' copyright on every text file."""
|
|
for f in ADDON.rglob("*"):
|
|
if f.is_dir() or f.suffix == ".png":
|
|
continue
|
|
text = f.read_text()
|
|
assert "Setti Solutions S.R.L" in text and "www.setti.md" in text, f
|
|
|
|
|
|
@pytest.mark.skipif(not HUB_WEB.exists(), reason="the Hub's panel is not in this repository")
|
|
def test_consent_to_control_as_the_hubs():
|
|
"""consent_control: off until the owner gives it; the bridge records the
|
|
Hub's control text and version (hub/.../cantabile/web), as the Cantabile
|
|
add-on does; no data consent (nothing leaves the home)."""
|
|
m = manifest()
|
|
assert m["options"]["consent_control"] is False and m["schema"]["consent_control"] == "bool"
|
|
assert "consent_data" not in m["schema"]
|
|
go = (ROOT / "src" / "eebus-bridge" / "consent.go").read_text()
|
|
text = re.search(r'ControlText\s*=\s*"([^"]+)"', go).group(1)
|
|
version = re.search(r'ConsentVersion\s*=\s*"([^"]+)"', go).group(1)
|
|
web = HUB_WEB.read_text()
|
|
hub_control = "".join(re.findall(r'"([^"]*)"', re.search(r"CONTROL_TEXT = M\((.*?)\)\n", web, re.S).group(1)))
|
|
assert text == hub_control
|
|
assert f'CONSENT_VERSION = "{version}"' in web
|
|
en = yaml.safe_load((ADDON / "translations" / "en.yaml").read_text())["configuration"]
|
|
assert text[len("Allow Cantabile"):-1] in " ".join(en["consent_control"]["description"].split())
|
|
docs = (ADDON / "DOCS.md").read_text()
|
|
assert "## Your consent" in docs and (ADDON / "CHANGELOG.md").exists()
|