cantabile_edge, cantabile_modbus, cantabile_eebus 0.1.1789: full source
This commit is contained in:
1 parent
94f46db8f8
commit
b24675fe9c
25 files changed
+766
-40
No files matched your search
@@ -51,7 +51,7 @@ from . import shades, steady
|
||||
from .evphases import EvPhases
|
||||
from .executor import Executor, building_msg
|
||||
from .gridorder import GridOrders
|
||||
from .guard import Guard
|
||||
from .guard import Guard, changed_by
|
||||
from .policy import Policy
|
||||
from .preferences import Preferences
|
||||
from .switchover import Switchover
|
||||
@@ -284,7 +284,7 @@ class Controller:
|
||||
value = st.get("s") # the agent last set the mode
|
||||
else:
|
||||
value = st.get("s")
|
||||
self.guard.observe(c.id, eid, value, now)
|
||||
self.guard.observe(c.id, eid, value, now, by=changed_by(st.get("c")))
|
||||
|
||||
def planned_kinds(self) -> set[str]:
|
||||
"""The kinds of the devices the box plans whose power is inside the
|
||||
@@ -411,6 +411,8 @@ class Controller:
|
||||
"sources": plan.get("sources", {}),
|
||||
# for the building (shed_w/grid_w per step, 24 h): absent from older agents
|
||||
"flex": plan.get("flex", {}),
|
||||
# the energy picture per step, 24 h (optimizer.plan_series; the console's plan chart): absent from older agents
|
||||
**({"series": plan["series"]} if plan.get("series") else {}),
|
||||
# the market's contracts in the plan (shadow): planned kWh and saving vs the grid
|
||||
"market": plan.get("market", []),
|
||||
# the owner's preferences: per level who set what and when, the
|
||||
@@ -843,7 +845,8 @@ class Controller:
|
||||
at level grid (the lower limit of the two holds)."""
|
||||
merged = {c: {q: dict(lv) for q, lv in qs.items()} for c, qs in self.saved_limits.items()}
|
||||
phases = {cid: v["phases"] for cid, v in self.ev_phases().items()}
|
||||
for cid, qs in self.gridorders.limits(self.controls, phases).items():
|
||||
self._grid_connected = self.ev_connected()
|
||||
for cid, qs in self.gridorders.limits(self.controls, phases, self._grid_connected).items():
|
||||
for q, (f, lim) in qs.items():
|
||||
per = merged.setdefault(cid, {}).setdefault(q, {})
|
||||
old = per.get("grid")
|
||||
@@ -882,8 +885,23 @@ class Controller:
|
||||
if a is not None:
|
||||
await self._publish("action", a)
|
||||
|
||||
def ev_connected(self) -> dict:
|
||||
"""Each charger's car: plugged in (True), not (False), unknown (None: no connected entity or no
|
||||
state yet), for the order's shares (gridorder.limits)."""
|
||||
out = {}
|
||||
for c in self.controls:
|
||||
if c.kind == "ev":
|
||||
st = self.col.state(c.entities["connected"]) if "connected" in c.entities else None
|
||||
out[c.id] = True if st == "on" else False if st == "off" else None
|
||||
return out
|
||||
|
||||
def grid_tick(self):
|
||||
"""An order that went stale or ended takes its limits away."""
|
||||
"""An order that went stale or ended takes its limits away; while one holds, a car plugged in or out
|
||||
gets its share again (the chargers share the one limit, gridorder.limits)."""
|
||||
if self.gridorders.active() and self.ev_connected() != getattr(self, "_grid_connected", None):
|
||||
self._merge_limits()
|
||||
self.wake.set()
|
||||
return
|
||||
if self.gridorders.order and not self.gridorders.active() and any(
|
||||
"grid" in lv for qs in self.guard.extra_limits.values() for lv in qs.values()) \
|
||||
and not any("grid" in lv for qs in self.saved_limits.values() for lv in qs.values()):
|
||||
|
||||
Reference in new issue
Block a user