cantabile_edge, cantabile_modbus, cantabile_eebus 0.1.676: full source

This commit is contained in:
Setti Solutions S.R.L committed 2026-11-04 10:33:14 +02:00
1 parent 3edd015039
commit d48b9aff87
32 files changed
+4633 -133

No files matched your search

+34
View File
@@ -56,6 +56,40 @@ async def backfill(client: HAClient, mapping, queue, since: datetime, until: dat
return batches
async def collect(client: HAClient, mapping, since: datetime, until: datetime, period: str = "hour",
want=None, consented: bool = True) -> dict[str, list[dict]]:
"""HA's statistics of the gauges (want(asset): which; consented: only
those with consent) as {asset: [{"start": unix, "mean"}]} in the assets'
units: for the box's own training history (trainhist.py, every mapped
gauge: nothing of it is queued or sent). A total of parts (pv.power from
pv.1.power, ...) has no entity of its own: left out."""
assets = {a.entity: a for a in mapping.assets
if (a.consent or not consented) and a.kind == "gauge" and not a.attribute and not a.equals
and (want is None or want(a.asset))}
if not assets:
return {}
meta = await client.send("recorder/list_statistic_ids", statistic_type="mean")
units = {m["statistic_id"]: m.get("statistics_unit_of_measurement") for m in meta}
ids = [e for e in assets if e in units]
out: dict[str, list[dict]] = {}
start = since
while start < until and ids:
end = min(start + CHUNK, until)
res = await client.send("recorder/statistics_during_period", timeout=300, start_time=start.isoformat(),
end_time=end.isoformat(), statistic_ids=ids, period=period, types=["mean"])
for eid, rows in (res or {}).items():
a, unit = assets.get(eid), units.get(eid)
if a is None:
continue
for r in rows:
v = number(r.get("mean"))
v = None if v is None else scaled(convert(v, unit, a.unit), a)
if v is not None:
out.setdefault(a.asset, []).append({"start": _ts(r["start"]), "mean": v})
start = end
return out
def parse_since(s: str) -> datetime:
"""An ISO date/time (UTC unless it says otherwise) or days back, e.g. 30d."""
if s.endswith("d") and s[:-1].isdigit():