cantabile_edge, cantabile_modbus, cantabile_eebus 0.1.1789: full source

This commit is contained in:
Setti Solutions S.R.L committed 2026-11-12 06:28:42 +02:00
1 parent 94f46db8f8
commit b24675fe9c
25 files changed
+766 -40

No files matched your search

+16 -2
View File
@@ -8,7 +8,16 @@ next window, so a steady sensor that reports rarely still has a mean.
Counters (a growing total: energy): the delta over the window. A total
that goes down is a meter reset or replacement: the new reading counts
from zero instead of a negative delta.
from zero instead of a negative delta. A drop is judged by the reading after
it: Home Assistant reports 0 for a moment while it restarts, and after a
restart it may show the total it had saved minutes before until the device
reports again, so a return to at least the previous total means the drop
was "unavailable" (the increase since the last real reading counts, no
reset); a reading below it means the meter really started again (a reset).
Before, the 0 was a reset, and the meter's whole total became one minute's
increase (a test site 2026-11-08 11:21 UTC: 2 124 kWh of load in a minute); the
stale total too (Sim Berlin 1 2026-11-08 14:44 UTC: heat.energy 462 477 →
461 809 Wh after the farm's reboot, back at 462 4xx with its simulator).
Unavailable: seconds of the window without a valid value are reported, so
the platform can tell "0 W" from "unknown".
@@ -39,6 +48,7 @@ class _Counter:
delta: float = 0.0
resets: int = 0
n: int = 0
drop: float | None = None # a reading below the total, judged by the next different one
@dataclass
@@ -58,11 +68,15 @@ class Aggregator:
if value is None:
return
if c.last is not None:
if value < c.last and (c.drop is None or value == c.drop or value == 0):
c.drop = value # unavailable until a different reading says otherwise
return
if value >= c.last:
c.delta += value - c.last
else:
c.delta += value
c.resets += 1
c.drop = None
c.last, c.n = value, c.n + 1
return
g = self.gauges.setdefault(asset, _Gauge(since=self.start))
@@ -90,6 +104,6 @@ class Aggregator:
for asset, c in sorted(self.counters.items()):
out.append({"asset": asset, "kind": "counter", "delta": c.delta, "last": c.last,
"resets": c.resets, "n": c.n})
self.counters[asset] = _Counter(last=c.last)
self.counters[asset] = _Counter(last=c.last, drop=c.drop)
self.start = end
return out