cantabile_edge, cantabile_modbus, cantabile_eebus 0.1.1030: full source
This commit is contained in:
1 parent
e2c7085d2c
commit
cddd34dcbc
30 files changed
+2141
-51
No files matched your search
@@ -277,6 +277,39 @@ def test_minimum_interval_between_moves():
|
||||
assert len(at) >= 2 and all(b - a >= 4 for a, b in zip(at, at[1:]))
|
||||
|
||||
|
||||
def test_a_shade_the_agent_moved_moves_back_in_the_next_plans():
|
||||
# 2026-11-05: Munich 1's shade closed for the night on 30 October and stayed
|
||||
# closed: every plan after the move started from the closed shade and no
|
||||
# longer knew why it was closed, so the morning's opening was never planned
|
||||
evening = ts(2026, 1, 15, 17)
|
||||
night = {"season": "heating"}
|
||||
assert moves(shades.schedule(shade(-1, pos=0), state(evening, t_out=2.0), night), evening) == []
|
||||
m = moves(shades.schedule(shade(-1, pos=0), state(evening, t_out=2.0), dict(night, ours="night")), evening)
|
||||
assert m[0][1:] == (100, "morning: open again") and m[0][0] >= "07:00", m
|
||||
# summer: shaded from the sun, opened again when the sun has left
|
||||
noon = ts(2026, 7, 15, 16)
|
||||
warm = {"temp_c": 26.0, "setpoint_c": 24.0}
|
||||
sch = shades.schedule(shade(270, pos=30), state(noon, steps=32), dict(warm, ours="shade"))
|
||||
assert moves(sch, noon)[0][1:] == (100, "the sun has left the west facade")
|
||||
# the rule each move is for, into the plan's entry
|
||||
start = ts(2026, 1, 15)
|
||||
sch = shades.schedule(shade(-1, pos=100), state(start, steps=192, t_out=2.0), night)
|
||||
assert [r for r, v in zip(sch["rule"], sch["set"]) if v is not None] == ["night", "", "night"]
|
||||
|
||||
|
||||
def test_moves_kept_while_the_shade_is_where_the_agent_put_it(tmp_path):
|
||||
mv = shades.Moves(str(tmp_path))
|
||||
assert mv.ours("curtain", 0.0) is None
|
||||
mv.record("curtain", "night", 0.0, 1_800_000_000)
|
||||
assert mv.ours("curtain", 2.0) == "night"
|
||||
assert mv.ours("curtain", 40.0) is None # moved by hand: the owner's position stays
|
||||
assert mv.ours("curtain", None) is None
|
||||
again = shades.Moves(str(tmp_path)) # across a restart
|
||||
assert again.ours("curtain", 0.0) == "night"
|
||||
again.record("curtain", "", 100.0, 1_800_050_000) # opened again: nothing of ours
|
||||
assert again.ours("curtain", 100.0) is None
|
||||
|
||||
|
||||
# -- the plan, the guard, the executor -----------------------------------------------------------
|
||||
|
||||
MAPPING = {"version": 3, "assets": [],
|
||||
@@ -460,3 +493,34 @@ def test_addon_devices_page_shade(tmp_path):
|
||||
return s.req(query=f"p=devices&d={dev_id}")
|
||||
de = contextvars.copy_context().run(run)
|
||||
assert "Raum und Fenster" in de and "Südosten" in de and "Bewegen durch Cantabile erlauben" in de
|
||||
|
||||
|
||||
def test_executor_keeps_what_a_planned_move_was_for(site):
|
||||
import asyncio
|
||||
from cantabile_edge.controller import Controller
|
||||
from cantabile_edge.config import Config
|
||||
m = Mapping.load(str(site / "mapping.yaml"))
|
||||
clk = Clock(float(ts(2026, 1, 15, 17)))
|
||||
cfg = Config(site_id="ab" * 16, mapping=str(site / "mapping.yaml"), state_dir=str(site))
|
||||
ctl = Controller(cfg, m, Consent(str(site)), sink=None, clock=clk)
|
||||
ctl.mode.set("auto", "test")
|
||||
ctl.col.on_entities({"a": {"cover.curtain": {"s": "open", "a": {"current_position": 100, "supported_features": 15}},
|
||||
"cover.rbs": {"s": "open", "a": {"supported_features": 11}}}})
|
||||
called = []
|
||||
|
||||
class Client:
|
||||
async def call_service(self, domain, service, entity, data, allowed):
|
||||
called.append((service, entity, data))
|
||||
t = int(clk.t)
|
||||
ctl.executor.plan = {"made": t, "devices": {
|
||||
"curtain": [{"t": t, "set": 0, "why": "night: closed to keep the warmth in", "rule": "night"}],
|
||||
"rbs": [{"t": t, "set": None, "why": ""}]}}
|
||||
asyncio.run(ctl.executor.tick(Client(), True))
|
||||
assert called == [("set_cover_position", "cover.curtain", {"position": 0})]
|
||||
ctl.col.on_entities({"c": {"cover.curtain": {"+": {"s": "closed", "a": {"current_position": 0}}}}})
|
||||
assert ctl.shade_ctx()["curtain"]["ours"] == "night" and "ours" not in ctl.shade_ctx()["rbs"]
|
||||
# kept across a restart: the next morning's plan opens it
|
||||
again = Controller(cfg, m, Consent(str(site)), sink=None, clock=clk)
|
||||
again.col.on_entities({"a": {"cover.curtain": {"s": "closed", "a": {"current_position": 0}}}})
|
||||
assert again.shade_ctx()["curtain"]["ours"] == "night"
|
||||
assert again.mode() == "auto" and again.mode.source().startswith("set by test at ")
|
||||
Reference in new issue
Block a user