cantabile_edge, cantabile_modbus, cantabile_eebus 0.1.901: full source
This commit is contained in:
1 parent
d48b9aff87
commit
e2c7085d2c
76 files changed
+5380
-330
No files matched your search
@@ -90,7 +90,7 @@ class Controller:
|
||||
self.mode = Mode(cfg.state_dir, cfg.mode)
|
||||
self.col = Collector()
|
||||
self.history = History(os.path.join(cfg.state_dir, "history.json"))
|
||||
self.bundles = Bundles(cfg.state_dir, cfg.site_id, cfg.default_price_ct)
|
||||
self.bundles = Bundles(cfg.state_dir, cfg.site_id)
|
||||
self.guard = Guard(self.controls, consent, self.mode, override_hold_s=cfg.override_hold_s,
|
||||
min_switch_s=cfg.min_switch_s, max_actions_per_hour=cfg.max_actions_per_hour, clock=clock)
|
||||
self.saved_limits = self._load_limits() # the console's (limits.json)
|
||||
@@ -256,8 +256,28 @@ class Controller:
|
||||
return {c.kind for c in self.controls if c.kind in ("heating", "cooling", "ev")}
|
||||
|
||||
# -- plans ---------------------------------------------------------------
|
||||
def owner_ratings(self):
|
||||
"""The owner's ratings of each control's device (the panel's Devices
|
||||
page: devices-specs.json, written by the Hub's devices tool) into
|
||||
the controls (Control.rated, rated_device): a battery's capacity,
|
||||
power and efficiency where the mapping and the device say none."""
|
||||
try:
|
||||
with open(os.path.join(self.cfg.state_dir, "devices-specs.json")) as f:
|
||||
specs = json.load(f).get("devices") or {}
|
||||
except (OSError, ValueError, AttributeError):
|
||||
specs = {}
|
||||
by = {}
|
||||
for d in specs.values() if isinstance(specs, dict) else []:
|
||||
if not isinstance(d, dict):
|
||||
continue
|
||||
for cid in d.get("controls") or []:
|
||||
by.setdefault(cid, (d.get("ratings") or {}, str(d.get("name") or "")))
|
||||
for c in self.controls:
|
||||
c.rated, c.rated_device = by.get(c.id, ({}, ""))
|
||||
|
||||
def model_state(self) -> dict:
|
||||
now = self.clock()
|
||||
self.owner_ratings()
|
||||
start = int(now // inputs_mod.STEP_S * inputs_mod.STEP_S)
|
||||
# sealed devices are not planned at all
|
||||
# and of a thermostat that heats and cools only its active side
|
||||
@@ -314,9 +334,11 @@ class Controller:
|
||||
self.executor.inputs_ok = self.inputs_fresh()
|
||||
self.act_now.set() # carry out a new plan now
|
||||
n = sum(len(v) for v in plan["devices"].values())
|
||||
log.info("plan %s (%s, %.1f s): %d changes in 48 h, %.2f EUR vs %.2f EUR baseline; %s",
|
||||
plan["id"], plan["status"], plan["solve_s"], n, plan["cost_eur"], plan["baseline_eur"],
|
||||
plan.get("price_note", ""))
|
||||
cost = (f"{plan['cost_eur']:.2f} EUR vs {plan['baseline_eur']:.2f} EUR baseline"
|
||||
if plan.get("cost_eur") is not None and plan.get("baseline_eur") is not None else "no cost (no tariff)")
|
||||
log.info("plan %s (%s, %.1f s): %d changes, %s; %s%s", plan["id"], plan["status"], plan["solve_s"], n, cost,
|
||||
plan.get("price_note", ""),
|
||||
"".join(f"; {k} not planned: {v['why']}" for k, v in (plan.get("refused") or {}).items()))
|
||||
await self._publish("plan", self.public_plan(plan))
|
||||
for cb in self.on_plan:
|
||||
await cb(plan)
|
||||
@@ -328,6 +350,9 @@ class Controller:
|
||||
"mode": plan["mode"], "devices": plan["devices"], "cost_eur": plan["cost_eur"],
|
||||
"baseline_eur": plan["baseline_eur"], "status": plan["status"],
|
||||
"prices": plan.get("price_note", ""), "model": plan.get("model", ""),
|
||||
# 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", {}),
|
||||
"sources": plan.get("sources", {}),
|
||||
# for the building (shed_w/grid_w per step, 24 h): absent from older agents
|
||||
"flex": plan.get("flex", {}),
|
||||
@@ -364,6 +389,8 @@ class Controller:
|
||||
while not stop.is_set():
|
||||
try:
|
||||
n = self.prefs.take_inbox({c.id: c for c in self.controls}, self.tz)
|
||||
while self.prefs.outbox: # the owner's own tariff to the cloud (link op own_tariff)
|
||||
await self._publish("own_tariff", self.prefs.outbox.pop(0))
|
||||
if n or self.prefs.prune(self.clock()):
|
||||
await self._prefs_changed()
|
||||
except Exception as e:
|
||||
@@ -417,7 +444,8 @@ class Controller:
|
||||
control at its safe default), and HA sends no update for an
|
||||
unchanged value, so its age says nothing."""
|
||||
for c in self.controls:
|
||||
for role in ("temp", "soc"):
|
||||
# a battery without its state of charge is not planned (inputs.battery_refusal), the rest is
|
||||
for role in ("temp",):
|
||||
if role in c.entities and self.col.value(c.entities[role]) is None:
|
||||
return False
|
||||
return True
|
||||
@@ -518,7 +546,8 @@ class Controller:
|
||||
try:
|
||||
await self.make_plan()
|
||||
except Exception as e:
|
||||
log.warning("plan: %s", e)
|
||||
# with its traceback: where it failed (the message alone did not say)
|
||||
log.warning("plan: %s", e, exc_info=True)
|
||||
self.wake.clear()
|
||||
woken = False
|
||||
try:
|
||||
|
||||
Reference in new issue
Block a user