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
@@ -23,7 +23,10 @@ Commands (from the console through the link, which checked the signature):
|
||||
limits {"asset", "quantity", "level": "cloud|building|grid",
|
||||
"floor"?, "limit"? (empty: none), "until"?}
|
||||
building {"v", "id", "building", "level", "control", "value", "from",
|
||||
"until", "why"}: the building's requests (building.py)
|
||||
"until", "why"}: the building's requests (building.py:
|
||||
load_limit, shift_request, thermostat_cap, battery_plan; a
|
||||
battery_plan also "schedule": "w0,w1,..." W per step and
|
||||
"step_s": "900", the building's plan its battery follows)
|
||||
preferences {"msg": JSON of preferences.apply_msg's {"set": {"item",
|
||||
"value"}}, "level": "installer|operator", "by"}: an installer's or
|
||||
Cantabile's setting within the owner's limits (preferences.py);
|
||||
@@ -44,7 +47,7 @@ import time
|
||||
from . import inputs as inputs_mod
|
||||
from .building import Building
|
||||
from .bundles import Bundles
|
||||
from . import steady
|
||||
from . import shades, steady
|
||||
from .evphases import EvPhases
|
||||
from .executor import Executor, building_msg
|
||||
from .gridorder import GridOrders
|
||||
@@ -63,19 +66,33 @@ MODES = ("off", "shadow", "advisory", "auto")
|
||||
class Mode:
|
||||
def __init__(self, state_dir: str, default: str):
|
||||
self.path, self.default = os.path.join(state_dir, "mode.json"), default
|
||||
self.at, self.by = None, "" # when and by whom the kept mode was set
|
||||
try:
|
||||
with open(self.path) as f:
|
||||
m = json.load(f).get("mode")
|
||||
d = json.load(f)
|
||||
m = d.get("mode")
|
||||
self.current = m if m in MODES else default
|
||||
if m in MODES:
|
||||
self.at, self.by = d.get("at"), str(d.get("by") or "")
|
||||
except (OSError, ValueError, AttributeError):
|
||||
self.current = default
|
||||
|
||||
def set(self, mode: str, by: str):
|
||||
tmp = self.path + ".tmp"
|
||||
now = int(time.time())
|
||||
with open(tmp, "w") as f:
|
||||
json.dump({"mode": mode, "at": int(time.time()), "by": by}, f)
|
||||
json.dump({"mode": mode, "at": now, "by": by}, f)
|
||||
os.replace(tmp, self.path)
|
||||
self.current = mode
|
||||
self.current, self.at, self.by = mode, now, by
|
||||
|
||||
def source(self) -> str:
|
||||
"""Where the mode in force comes from, in words (the startup log):
|
||||
the console's command kept in mode.json, or the configuration."""
|
||||
if self.at is None:
|
||||
return "from the configuration"
|
||||
when = time.strftime("%Y-%m-%d %H:%M UTC", time.gmtime(self.at)) if isinstance(self.at, (int, float)) else "?"
|
||||
cfg = f"; the configuration says {self.default}" if self.default != self.current else ""
|
||||
return f"set by {self.by or 'the console'} at {when}, kept in {self.path}{cfg}"
|
||||
|
||||
def __call__(self) -> str:
|
||||
return self.current
|
||||
@@ -107,6 +124,7 @@ class Controller:
|
||||
self.building = Building(cfg.state_dir, clock)
|
||||
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
|
||||
self.col.observers.append(self._observe)
|
||||
self.client = None
|
||||
self.tz = "UTC"
|
||||
@@ -204,6 +222,12 @@ class Controller:
|
||||
ctx["temp_c"] = self._asset_value(ta)
|
||||
if ctx.get("setpoint_c") is None:
|
||||
ctx["setpoint_c"] = self._asset_value(sa)
|
||||
# what the agent last moved it for, while it is still there (shades.Moves)
|
||||
moves = getattr(self.executor, "shade_moves", None)
|
||||
if moves is not None and "cover" in c.entities:
|
||||
ours = moves.ours(c.id, inputs_mod.cover_position(self.col, c.entities["cover"]))
|
||||
if ours:
|
||||
ctx["ours"] = ours
|
||||
out[c.id] = ctx
|
||||
return out
|
||||
|
||||
@@ -353,6 +377,8 @@ class Controller:
|
||||
# without a tariff: priced false, cost and baseline null (U1); controls not
|
||||
# planned and why (U2); absent from older agents
|
||||
"priced": plan.get("priced", True), "refused": plan.get("refused", {}),
|
||||
# what the plan assumed for want of a fact (e.g. battery.end_value_pct missing)
|
||||
"notes": plan.get("notes", []),
|
||||
"sources": plan.get("sources", {}),
|
||||
# for the building (shed_w/grid_w per step, 24 h): absent from older agents
|
||||
"flex": plan.get("flex", {}),
|
||||
|
||||
Reference in new issue
Block a user