OPT-27 round 3: a kept figure is at most 12 h old; DST-safe midnight bound; pruning test
checks / unit (pull_request) Successful in 15m37s
infra-pin / fresh (pull_request) Successful in 1s

F1: the evening rule has an age limit (KEPT_MAX_AGE_S).
F2: the evening bound is the next local midnight (_bounds), right on 25 h and 23 h days.
F5: test that old days are dropped from the stored hold.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
glenn schrooyen
2026-10-30 20:41:34 +01:00
co-authored by Claude
parent 307cb47caf
commit 13b61d586a
4 changed files with 81 additions and 5 deletions
+8 -3
View File
@@ -64,6 +64,9 @@ BELL_FROM_H, BELL_TO_H = 6.0, 20.0
# OPT-27: a kept reading serves the night plan from the end of the bell until
# this many hours after local midnight (the card: "local midnight + 3 h").
KEPT_UNTIL_H = 3.0
# OPT-27: and a reading older than this when used is not kept (a morning
# figure must not drive the night).
KEPT_MAX_AGE_S = 12 * 3600.0
SAVE_EVERY_S = 900.0
# Why there is no forecast (the page words are in ui_text `home_words`).
@@ -318,7 +321,8 @@ class Hold:
The kept reading must be for `day0`, and either (a) at most `FRESH_S`
old, or (b) used at night: from the end of the bell to local midnight,
or within `KEPT_UNTIL_H` after it. `kept` is true when (b) was needed,
or within `KEPT_UNTIL_H` after it, and then at most `KEPT_MAX_AGE_S`
old. `kept` is true when (b) was needed,
or `as_today` (a tomorrow figure standing in for today, after
midnight)."""
rec = self._r.get((kind, entity, day0))
@@ -327,11 +331,12 @@ class Hold:
day, at = rec
if (now - at).total_seconds() <= FRESH_S and not as_today:
return day, at, False
if (now - at).total_seconds() > KEPT_MAX_AGE_S:
return None
# 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)
evening = _local_hour(now) >= BELL_TO_H and now < _bounds(day0)[1]
if as_today:
return (day, at, True) if after_midnight else None
return (day, at, True) if (evening or after_midnight) else None