From 6004bfad9ae8c62b0ccb642cdf11c9e53a34591a Mon Sep 17 00:00:00 2001 From: glenn schrooyen Date: Thu, 12 Nov 2026 08:15:01 +0100 Subject: [PATCH] MAINT-24: read the last row without a bare index (test_named_absence) Co-Authored-By: Claude --- goodwe_controller/test_maint24.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/goodwe_controller/test_maint24.py b/goodwe_controller/test_maint24.py index e9f061c..273cf98 100644 --- a/goodwe_controller/test_maint24.py +++ b/goodwe_controller/test_maint24.py @@ -124,15 +124,16 @@ CH = sc.MAINT_CHARGE print("1. A in maintenance CHARGE, B a charger in the cheap window") rows, st, c = scen(a=CH) ma, mb = mean(rows, "a"), mean(rows, "b") +last = rows[-1] if rows else {} print(f" A {ma:+.0f} W, B {mb:+.0f} W, worst quarter {worst_quarter(st):.0f}" - f" W, why {rows[-1]['why']}, roles {rows[-1]['roles']}") + f" W, why {last.get('why')}, roles {last.get('roles')}") check("A charges at (5950 - 3000) / 2 = 1475 W, not 0 or a few hundred W", -1500.0 <= ma <= -1440.0) check("B files no grid trade: no trade action in the run, B near 0 W", all("CHARGE" not in str(r["action"]) for r in rows) and mb > -50.0) check("roles: B does not charge, and the why is 'cycle'", all(r["roles"].get(B) != "charge" for r in rows) - and rows[-1]["why"] == "cycle") + and last.get("why") == "cycle") check("every quarter at or under the month aim", worst_quarter(st) <= AIM + 1.0) check("A never gives back while there is no real peak", @@ -169,12 +170,13 @@ check("no banked peak: the aim is cap - margin (3450 W) as before, so A " print("\n3. the mirror: B in maintenance CHARGE, A the charger") rowsm, stm, cm = scen(b=CH, soc=(30.0, 49.0)) mam, mbm = mean(rowsm, "a"), mean(rowsm, "b") +lastm = rowsm[-1] if rowsm else {} print(f" A {mam:+.0f} W, B {mbm:+.0f} W, worst quarter " - f"{worst_quarter(stm):.0f} W, why {rowsm[-1]['why']}") + f"{worst_quarter(stm):.0f} W, why {lastm.get('why')}") check("B charges at 1475 W, A files no grid trade, why 'cycle'", -1500.0 <= mbm <= -1440.0 and mam > -50.0 and all("CHARGE" not in str(r["action"]) for r in rowsm) - and rowsm[-1]["why"] == "cycle" + and lastm.get("why") == "cycle" and all(r["roles"].get(A) != "charge" for r in rowsm)) check("...every quarter at or under the month aim", worst_quarter(stm) <= AIM + 1.0)