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
@@ -89,7 +89,8 @@ def _val(c, e):
|
||||
|
||||
def _big(c, old, new) -> bool:
|
||||
if c.kind == "battery":
|
||||
top = max(float(c.p("max_charge_w")), float(c.p("max_discharge_w")))
|
||||
f, _, _ = c.battery_facts()
|
||||
top = max(f.get("max_charge_w") or 0.0, f.get("max_discharge_w") or 0.0)
|
||||
return abs(new - old) >= max(MIN_BATTERY_W, BATTERY_SHARE * top) - 1e-9
|
||||
if c.kind in ("heating", "cooling"):
|
||||
return abs(new - old) >= TEMP_K - 1e-9
|
||||
@@ -129,9 +130,10 @@ def stabilise(plan: dict, state: dict, controls, col, last_set=None, now: float
|
||||
In place; returns the plan."""
|
||||
now = plan.get("made", 0) if now is None else now
|
||||
step = plan.get("step_s", 900)
|
||||
end = plan.get("start", now) + step * state.get("steps", 192)
|
||||
prices = state.get("price_import") or []
|
||||
feed = state.get("price_export") or []
|
||||
end = plan.get("start", now) + step * plan.get("steps", state.get("steps", 192))
|
||||
# the prices the plan had (none without a tariff: no gain to weigh then)
|
||||
prices = [x for x in state.get("price_import") or [] if x is not None]
|
||||
feed = [x for x in state.get("price_export") or [] if x is not None]
|
||||
spread = (max(prices) - min(prices + feed)) if prices else 0.0 # ct per kWh, at most
|
||||
devs = {d["id"]: d for d in state.get("devices") or []}
|
||||
kept_n = 0
|
||||
@@ -158,6 +160,9 @@ def stabilise(plan: dict, state: dict, controls, col, last_set=None, now: float
|
||||
out = []
|
||||
for i, e in enumerate(raw):
|
||||
new = _val(c, e)
|
||||
if new == "release":
|
||||
out.append(e) # nothing written (a room's fallback: its own setpoint)
|
||||
continue
|
||||
if _same(cur, new):
|
||||
kind = None
|
||||
elif isinstance(cur, str) or isinstance(new, str):
|
||||
@@ -198,11 +203,13 @@ def stabilise(plan: dict, state: dict, controls, col, last_set=None, now: float
|
||||
changed[kind] = t
|
||||
if kind == "mode" and c.kind != "battery":
|
||||
changed["set"] = t
|
||||
_hold_source(c, out, col, hold["mode"], last_set, now)
|
||||
# a plan lists changes only
|
||||
merged = []
|
||||
for e in out:
|
||||
if merged and _same(_val(c, merged[-1]), _val(c, e)) and \
|
||||
(merged[-1].get("grid") == e.get("grid") or _val(c, e) == AUTO):
|
||||
(merged[-1].get("grid") == e.get("grid") or _val(c, e) == AUTO) and \
|
||||
merged[-1].get("source") == e.get("source"):
|
||||
continue
|
||||
merged.append(e)
|
||||
plan["devices"][c.id] = merged
|
||||
@@ -210,6 +217,31 @@ def stabilise(plan: dict, state: dict, controls, col, last_set=None, now: float
|
||||
return plan
|
||||
|
||||
|
||||
def _hold_source(c, entries, col, hold_s, last_set, now):
|
||||
"""A hybrid's heat source (a plan entry's "source") changes only after
|
||||
the hold of a mode (params.hold_mode_s) since its last change: from the
|
||||
agent's last command (the guard's record, kind "source"), then from the
|
||||
plan's own changes. A held entry keeps the source in force, its why
|
||||
says so. In place."""
|
||||
if c.kind != "heating" or "source" not in c.entities:
|
||||
return
|
||||
opts = {str(v): k for k, v in (c.p("source_options") or {}).items()}
|
||||
cur = opts.get(str(col.state(c.entities["source"])))
|
||||
t_last = last_set(c.id, "source") if last_set else None
|
||||
t_last = t_last if t_last is not None else -1e18
|
||||
for e in entries:
|
||||
new = e.get("source")
|
||||
if new is None or new == cur:
|
||||
continue
|
||||
t = max(e["t"], now)
|
||||
if cur is not None and t - t_last < hold_s:
|
||||
e["planned_source"], e["source"] = new, cur
|
||||
e["why"] = (e.get("why", "") + "; " if e.get("why") else "") + \
|
||||
f"source kept: changed {int((t - t_last) // 60)} min ago (hold {hold_s / 60:.0f} min)"
|
||||
continue
|
||||
cur, t_last = new, t
|
||||
|
||||
|
||||
def _amount(c, a, b) -> str:
|
||||
unit = {"battery": "W", "heating": "K", "cooling": "K", "ev": "A"}[c.kind]
|
||||
d = abs(b - a)
|
||||
|
||||
Reference in new issue
Block a user