cantabile_edge, cantabile_modbus, cantabile_eebus 0.1.2019: full source

This commit is contained in:
Setti Solutions S.R.L committed 2026-11-12 21:05:22 +00:00
1 parent c0a6f8a579
commit 5168a4a590
27 files changed
+2815 -126

No files matched your search

+38 -2
View File
@@ -47,7 +47,7 @@ import time
from . import inputs as inputs_mod
from .building import Building
from .bundles import Bundles
from . import shades, steady
from . import comfort, shades, steady
from .evphases import EvPhases
from .executor import Executor, building_msg
from .gridorder import GridOrders
@@ -129,6 +129,9 @@ class Controller:
self.executor = Executor(self.controls, self.guard, self.col, self._publish, stale_s=cfg.plan_stale_s,
clock=clock, building=self.building)
self.executor.shade_moves = shades.Moves(cfg.state_dir) # what each shade was last moved for
# the household's tolerance learnt from its changes by hand (comfort.py, methods.md G5)
self.tolerance = comfort.Tolerance(cfg.state_dir)
self.executor.on_override = self._learn_override
self.col.observers.append(self._observe)
self.client = None
self.tz = "UTC"
@@ -243,6 +246,9 @@ class Controller:
ours = moves.ours(c.id, inputs_mod.cover_position(self.col, c.entities["cover"]))
if ours:
ctx["ours"] = ours
if self.guard.overridden(c.id):
# moved by hand: the plan keeps it there while the guard keeps off it (G3: the override wins)
ctx["held_until"] = self.guard._t(c.id).override_until
out[c.id] = ctx
return out
@@ -329,7 +335,8 @@ class Controller:
grid_order=self.gridorders.for_model(start, inputs_mod.STEP_S, inputs_mod.STEPS),
grid_max_w=getattr(self.cfg, "grid_max_w", None),
ev_phases=self.ev_phases(), presence=self.presence_entities(),
storefit=self.storefit)
storefit=self.storefit,
comfort_ctx={"mode": self.prefs.comfort_mode(), "tolerance": self.tolerance})
# the owner's preferences per step (preferences.py)
return self.prefs.apply(state, {c.id: c for c in controls}, self.col, now)
@@ -628,6 +635,10 @@ class Controller:
now = self.clock()
self.history.add("load_w", inputs_mod.base_load(self.col, self.inputs), now)
self.history.add("pv_w", self.col.total(self.inputs.pv_power), now)
try:
self.sample_climate(now)
except Exception as e: # never stops the actions
log.warning("climate history: %s", e)
if self.sample_ev_phases(now) and self.gridorders.active():
self._merge_limits() # a learned count: the order's current bound again
try:
@@ -797,6 +808,31 @@ class Controller:
changed |= self.evphases.sample(c.id, p, a, float(c.p("voltage")), now)
return changed
def _learn_override(self, ev: dict):
"""A change by hand to a planned room's setpoint (the guard's
override): into the household's tolerance (comfort.Tolerance, G5).
Only a thermostat's setpoint against the plan's own (not a
command's)."""
c = next((x for x in self.controls if x.id == ev.get("control")), None)
if c is None or c.kind not in ("heating", "cooling") or ev.get("level", "plan") != "plan":
return
if ev.get("entity") != c.entities.get("climate"):
return
self.tolerance.record(c.id, c.kind, ev.get("agent_set"), ev.get("value"), ev.get("at") or self.clock())
# -- the climate's history: the comfort band's running mean, the flat's mass (G2, G5) ----
def sample_climate(self, now: float):
"""The outdoor temperature now ("t_out") and each heating or cooling
control's room temperature ("room:<id>") into the history (8 days):
the comfort band's running mean outdoor temperature (comfort.py) and
the flat's mass now (inputs.mass_start)."""
self.history.add("t_out", inputs_mod.outdoor_now(self.col, self.inputs), now)
for c in self.controls:
if c.kind in ("heating", "cooling"):
t = inputs_mod.device_state(c, self.col, now).get("temp_c")
if t is not None:
self.history.add(f"room:{c.id}", float(t), now)
# -- what the box learns of its stores (storefit.py) ---------------------------
def sample_stores(self, now: float):
"""A reading of each battery (its SoC, its own power, the PV, its