OPT-27 round 2: a kept tomorrow figure is bounded on both sides
checks / unit (pull_request) Successful in 55m40s
infra-pin / fresh (pull_request) Successful in 1s

Hold.stand_in(): day0 <= now < day0 + 3 h. A tomorrow sensor is asked with
day0 = the next midnight, so the upper bound alone was true all day and a
figure stood in at any hour. test_opt27.py covers daytime tomorrow outages.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
glenn schrooyen
2026-10-29 23:11:44 +01:00
co-authored by Claude
parent 1eb572f513
commit f095ca9268
2 changed files with 19 additions and 1 deletions
+3 -1
View File
@@ -315,7 +315,9 @@ class Hold:
day, at = rec
if (now - at).total_seconds() <= FRESH_S and not as_today:
return day, at, False
after_midnight = now < day0 + timedelta(hours=KEPT_UNTIL_H)
# Both sides: a tomorrow sensor is asked with day0 = the next
# midnight, which is in the future all day (round 2).
after_midnight = day0 <= now < day0 + timedelta(hours=KEPT_UNTIL_H)
evening = _local_hour(now) >= BELL_TO_H and now < day0 + timedelta(
days=1)
if as_today:
+16
View File
@@ -136,6 +136,22 @@ check("daytime: an outage under 3 h is covered, one over 3 h is not",
check("daytime: a sensor that stopped is stale after 3 h, as before "
"(the hold does not start before the bell ends)", d_out2 is None)
# Round 2: today fresh, tomorrow's sensor stopped or down in the daytime.
h9 = solarfc.Hold()
rs(st(5.0, at(4, 9, 5)), st(12.0, at(4, 9, 5)), at(4, 9, 6), h9)
for label, tm in (("stale", st(12.0, at(4, 9, 5))), ("unavailable", GONE)):
fd = rs(st(3.0, at(4, 13, 55)), tm, at(4, 14, 0), h9)[0]
check(f"14:00, today fresh, tomorrow {label} since 09:05 (over 3 h): "
"no tomorrow, nothing kept",
fd is not None and fd.tomorrow is None and not fd.kept)
fn = rs(st(0.1, at(4, 20, 55)), tm, at(4, 21, 0), h9)[0]
check(f"21:00, tomorrow {label}: the 09:05 figure covers it, kept",
fn is not None and fn.tomorrow is not None
and fn.tomorrow.kwh == 12.0 and fn.kept)
fs = rs(st(3.0, at(4, 10, 55)), tm, at(4, 11, 0), h9)[0]
check(f"11:00, tomorrow {label} for under 3 h: still covered, not kept",
fs is not None and fs.tomorrow is not None and not fs.kept)
# The bound: midnight + 3 h, and the day a figure is for.
fm = rs(st(0.0, at(3, 23, 0)), st(0.0, at(3, 23, 0)), at(4, 1, 0), h2)[0]
check("00:30 is covered by the 18:05 tomorrow figure, as TODAY's",