cantabile_edge, cantabile_modbus, cantabile_eebus 0.1.650: full source
This commit is contained in:
1 parent
85edd56ec8
commit
3edd015039
20 files changed
+2021
-35
No files matched your search
@@ -35,6 +35,7 @@ import time
|
||||
from . import inputs as inputs_mod
|
||||
from .building import Building
|
||||
from .bundles import Bundles
|
||||
from . import steady
|
||||
from .evphases import EvPhases
|
||||
from .executor import Executor, building_msg
|
||||
from .gridorder import GridOrders
|
||||
@@ -102,6 +103,7 @@ class Controller:
|
||||
self.plan_error = ""
|
||||
self.forecast: list[dict] = [] # the weather entity's hourly forecast
|
||||
self.wake = asyncio.Event()
|
||||
self.calm = False # the next plan is for a bundle only: the quarter under way stays
|
||||
self.act_now = asyncio.Event() # a control, release or new plan: act at once
|
||||
self.on_plan = [] # callbacks (the announcer) when a plan is made
|
||||
self.received: list[dict] = [] # the last commands and bundles (shown in HA, announce.py)
|
||||
@@ -242,6 +244,12 @@ class Controller:
|
||||
self.plan_error = plan["error"]
|
||||
log.warning("no new plan: %s (the last one stays while fresh)", plan["error"])
|
||||
return None
|
||||
calm, self.calm = self.calm, False
|
||||
if calm:
|
||||
steady.carry_quarter(plan, self.plan, self.clock())
|
||||
# changes that do not matter stay out of it (deadband, hold, gain: steady.py)
|
||||
steady.stabilise(plan, state, [c for c in self.controls if c.id in plan.get("devices", {})], self.col,
|
||||
self.guard.last_change, self.clock())
|
||||
plan["mode"] = self.mode()
|
||||
plan["id"] = f"{self.cfg.site_id[:8]}-{plan['made']}"
|
||||
plan["model"] = self.bundles.model_id()
|
||||
@@ -357,6 +365,7 @@ class Controller:
|
||||
d != {}, f.error or "stored")
|
||||
last = now
|
||||
log.info("plan: a new tariff or model: planning again")
|
||||
self.calm = True # nothing urgent: from the next quarter (steady.carry_quarter)
|
||||
self.wake.set()
|
||||
|
||||
async def _planner(self, stop):
|
||||
@@ -380,7 +389,7 @@ class Controller:
|
||||
await asyncio.wait_for(asyncio.wait([asyncio.ensure_future(stop.wait()),
|
||||
asyncio.ensure_future(self.wake.wait())],
|
||||
return_when=asyncio.FIRST_COMPLETED),
|
||||
self.cfg.control_interval_s)
|
||||
plan_wait(self.clock(), self.cfg.control_interval_s))
|
||||
woken = self.wake.is_set()
|
||||
except asyncio.TimeoutError:
|
||||
pass
|
||||
@@ -656,3 +665,20 @@ async def solve(state: dict, timeout: float) -> dict:
|
||||
return json.loads(out)
|
||||
except ValueError:
|
||||
return {"error": (err.decode(errors="replace").strip().splitlines() or ["no output"])[-1][:300]}
|
||||
|
||||
|
||||
PLAN_AT_S = 5.0 # a plan this long after a quarter hour: its first step is the quarter just begun
|
||||
|
||||
|
||||
def plan_wait(now: float, interval: float, at: float = PLAN_AT_S) -> float:
|
||||
"""Seconds to the next regular plan: just after the next boundary of
|
||||
the interval (the quarter hours), not interval after the last plan. A
|
||||
plan made mid-quarter takes the room as it is now for the quarter's
|
||||
start, and its first step's setpoint differed from the plan before it
|
||||
for that same quarter: a heat pump was set 20.5 at the quarter hour and
|
||||
back to 20.0 when the next plan came 12 minutes later (sim-munich-1,
|
||||
2026-11-03)."""
|
||||
if interval <= 0:
|
||||
return 0.0
|
||||
nxt = (now - at) // interval * interval + interval + at
|
||||
return max(1.0, nxt - now)
|
||||
Reference in new issue
Block a user