From 513183aba3930b65af3763a2a7dfb1551d7d5feb Mon Sep 17 00:00:00 2001 From: glenn schrooyen Date: Thu, 1 Oct 2026 00:56:34 +0200 Subject: [PATCH] test_peak_margin: read the month peak on the runs' clock, not today's Part 3 read the simulated September's peak with the wall clock, so from 2026-10-01 it read no peak and crashed on every tree (4ad8298 too). Co-Authored-By: Claude Opus 5.5 --- goodwe_controller/test_peak_margin.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/goodwe_controller/test_peak_margin.py b/goodwe_controller/test_peak_margin.py index 0631b57..f8da15c 100644 --- a/goodwe_controller/test_peak_margin.py +++ b/goodwe_controller/test_peak_margin.py @@ -173,14 +173,15 @@ check("...and decide() sizes the floor to land the quarter 50 W under it " # ============================================================================ # print("\n3. the bill and the reports keep the real cap") _c = _runs["n1_off", None][1] -_pk = _c.peak.peak().peak_w +_t = rig.rig.BASE # the runs' clock, not the wall clock (a new month) +_pk = _c.peak.peak(_t).peak_w print(f" month peak {_pk:.0f} W, tracker cap {_c.peak.cap_w:.0f} W, " - f"warning {_c.peak.warning_frac():.3f}, headroom " - f"{_c.peak.headroom_w():.0f} W") + f"warning {_c.peak.warning_frac(_t):.3f}, headroom " + f"{_c.peak.headroom_w(_t):.0f} W") check("test_billing_uses_cap: the month-peak tracker (bill, headroom, 80 % " "warning) is built on the real cap, not cap - margin", - _c.peak.cap_w == CAP and _c.peak.warning_frac() == _pk / CAP - and _c.peak.headroom_w() == CAP - _pk) + _c.peak.cap_w == CAP and _c.peak.warning_frac(_t) == _pk / CAP + and _c.peak.headroom_w(_t) == CAP - _pk) _eng = [g for r in _runs["n1_off", None][0] for g in (r[-1][1],) if g and g[0] and g[1]] print(f" {len(_eng)} engaged cycles; one: {_eng[0][4] if _eng else None}")