cantabile_edge, cantabile_modbus, cantabile_eebus 0.1.901: full source

This commit is contained in:
Setti Solutions S.R.L committed 2026-11-05 13:14:49 +02:00
1 parent d48b9aff87
commit e2c7085d2c
76 files changed
+5380 -330

No files matched your search

+72 -1
View File
@@ -13,7 +13,7 @@ import pytest
import yaml
from cantabile_edge import i18n, propose
from cantabile_edge.devpage import App, Devices
from cantabile_edge.devpage import App, Devices, SupportSessions
from cantabile_edge.joinpage import Fleet
from cantabile_edge.mapping import Mapping
@@ -302,6 +302,77 @@ def test_german(tmp_path):
assert "Use with Cantabile" not in out
def test_support_session_banner_end_and_owners_choices(tmp_path):
"""Remote HA for support on an add-on site: while the link says support
has this Home Assistant open, both pages show it with End now (SIGUSR1
to the link, only to the link); the support user cannot change what is
the owner's (as on the Hub's panel)."""
import signal
import time
s = Site(tmp_path)
link, proc, killed = tmp_path / "link", tmp_path / "proc", []
link.mkdir()
(proc / "4242").mkdir(parents=True)
(proc / "4242" / "cmdline").write_bytes(b"cantabile-link\0")
(proc / "77").mkdir()
(proc / "77" / "cmdline").write_bytes(b"python3\0-m\0cantabile_edge\0")
s.app.support = SupportSessions(str(link), proc=str(proc), kill=lambda pid, sig: killed.append((pid, sig)))
state = link / "support-ha.json"
assert "Cantabile support has this Home Assistant open" not in s.req() # no file: none
state.write_text(json.dumps({"pid": 4242, "sessions": []}))
assert "Cantabile support has this Home Assistant open" not in s.req()
state.write_text(json.dumps({"pid": 4242, "user": "Cantabile support", "sessions": [
{"by": "Ana (Cantabile)", "since": int(time.time()) - 300, "consent": "", "kind": "ha"}]}))
out = s.req()
assert "Cantabile support has this Home Assistant open" in out and "Ana (Cantabile), for 5 minutes" in out
assert 'value="end-support"' in out and "End now" in out
assert "Cantabile support has this Home Assistant open" in s.req(query="p=building")
def german():
i18n.use("de")
return s.req()
import contextvars
out = contextvars.copy_context().run(german)
assert "Der Cantabile-Support hat dieses Home Assistant geöffnet" in out and "seit 5 Minuten" in out
assert "Jetzt beenden" in out
# the owner's End now (any administrator): the link gets SIGUSR1
out = s.req("POST", "p=devices", {"do": "end-support"})
assert "Ended. Cantabile support's session is closed" in out and killed == [(4242, signal.SIGUSR1)]
out = s.req("POST", "p=building", {"do": "end-support"})
assert "Ended." in out and "<nav>" in out and len(killed) == 2
# never another process: a pid that is not the link
state.write_text(json.dumps({"pid": 77, "sessions": [{"by": "Ana", "since": 1, "kind": "ha"}]}))
assert "No session to end" in s.req("POST", "p=devices", {"do": "end-support"}) and len(killed) == 2
state.write_text(json.dumps({"pid": 4242, "sessions": [{"by": "Ana", "since": 1, "kind": "ha"}]}))
# the support user (an HA administrator) may look and add, not decide what is the owner's
s.give_consent(share=True, control=True)
s.post(do="use", ha_device=AC, profile="ha-thermostat")
dev_id = next(iter(s.devices()))
sup = {"x-remote-user-id": "u-support", "x-remote-user-name": "cantabile-support",
"x-remote-user-display-name": "Cantabile support"}
s.ha.admins.add("u-support")
ingress = "172.30.32.2"
frag = s.tmp / "mapping.d" / f"{dev_id}.yaml"
for form, why in (({"do": "consent", "id": dev_id, "read": "1", "control": "1"}, "Reading and control are the owner"),
({"do": "protect", "id": dev_id, "target": f"device:{dev_id}", "level": "none"}, "Protection is the owner"),
({"do": "switchover", "id": dev_id, "mode": "cooling"}, "Heating or cooling is the owner"),
({"do": "weather", "id": dev_id}, "The weather forecast is the owner")):
before = (s.state / "devices.json").read_text(), frag.read_text()
out = s.req("POST", f"p=devices&d={dev_id}", form, sup, ingress)
assert why in out and "Cantabile support has this Home Assistant open" in out, form
assert before == ((s.state / "devices.json").read_text(), frag.read_text()), form
# the owner still can
s.req("POST", f"p=devices&d={dev_id}", {"do": "consent", "id": dev_id, "read": "1", "control": "0"})
assert s.devices()[dev_id] != json.loads(before[0])[dev_id]
# known by its id too while a session is open (the link names it)
state.write_text(json.dumps({"pid": 4242, "sessions": [{"by": "Ana", "since": 1, "kind": "ha", "ha_user": "u-support"}]}))
out = s.req("POST", f"p=devices&d={dev_id}", {"do": "protect", "id": dev_id, "target": f"device:{dev_id}", "level": "none"},
{"x-remote-user-id": "u-support"}, ingress)
assert "Protection is the owner" in out
# and End now is theirs too
assert "Ended." in s.req("POST", "p=devices", {"do": "end-support"}, sup, ingress)
@pytest.fixture(autouse=True)
def english():
i18n.use("en")