EV-20 rig round 2: a short charger read gap keeps the last reading; ha_signed pause timed from the meter age
checks / unit (pull_request) Failing after 43m21s
infra-pin / fresh (pull_request) Failing after 2s

A charger reading missing for less than stale_input_s keeps the last trusted
reading in CarTracker (shared by Solar, Manual and the peak guard): no
decision or write in that cycle, no stuck arm or clear. At stale_input_s the
safe path is unchanged. This also stops the false PEAK_GUARD_FLOOR_LIMITED
after one gap (EV-18 T10(b) updated). On ha_signed Solar's unknown-sun pause
comes at meter age meter_max_age_s + ev_pause_min, checked every cycle.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VSY9UpTaUYnjJF5oVtbM1w
This commit is contained in:
Claude
2026-11-23 23:46:48 +01:00
parent 09b6af919b
commit 8d62abe36b
6 changed files with 198 additions and 8 deletions
+12 -3
View File
@@ -498,8 +498,12 @@ class SunInputs:
def __init__(self, target_w=None, hold=False, auto=True, start_s=120.0,
pause_s=300.0, spare_w=None, room_w=0.0, margin_w=100.0,
first=DEFAULT_FIRST):
first=DEFAULT_FIRST, unknown_s=0.0):
self.target_w, self.hold, self.auto = target_w, hold, auto
# EV-20 rig round 2: how long the sun has already been unknown when
# the cause is the meter's own age (`ha_signed`): the pause is timed
# from that age, not from the cycle that noticed it.
self.unknown_s = unknown_s
self.start_s, self.pause_s = start_s, pause_s
self.spare_w, self.room_w, self.margin_w = spare_w, room_w, margin_w
self.first = first
@@ -563,7 +567,7 @@ class SolarPlan:
self.switch, self._before = False, None
def step(self, now, *, target_w, n_now, auto, clamp, start_s, pause_s,
hold=False, gap_ok=True):
hold=False, gap_ok=True, unknown_s=0.0):
"""`n_now`: the phases the car draws on now (1 for a one-phase car);
`auto`: Solar may choose the phases; `gap_ok`: a phase change is
allowed now (EV-04's one per `PHASE_GAP_S`); `hold`: readings late
@@ -586,6 +590,11 @@ class SolarPlan:
if self.a > 0.0:
if self.unknown_since is None:
self.unknown_since = now
if unknown_s > 0.0:
# ha_signed: unknown since the meter's age passed its
# bound, so the pause comes at that age + `pause_s`.
self.unknown_since = min(self.unknown_since,
now - unknown_s)
# A hold that began on a known low spare still ends on time.
if now - self.unknown_since >= pause_s or (
self.low_since is not None
@@ -919,7 +928,7 @@ class SolarWriter(ManualWriter):
now, target_w=sun.target_w, hold=sun.hold, n_now=n_now,
auto=sun.auto and not self.single and not self.phases_gave_up,
clamp=clamp, start_s=sun.start_s, pause_s=sun.pause_s,
gap_ok=gap_ok)
gap_ok=gap_ok, unknown_s=getattr(sun, "unknown_s", 0.0))
@staticmethod
def _drawing(r) -> bool:
+19
View File
@@ -719,6 +719,7 @@ class CarTracker:
# write went out, kept at `begin_write` (the arming baseline). Empty: no
# write begun, and `note_write` uses `sig`.
pre_sig: tuple = ()
held: bool = False # EV-20: the last reading stands in for a gap
armed_at: float | None = None
armed_sig: tuple | None = None
sig: tuple | None = None
@@ -735,6 +736,17 @@ class CarTracker:
persist: bool = False # set when `today` changed, for the store
def observe(self, r: ChargerReading, now: float, now_utc, day: str):
if not r.available and self.bad_since is None:
self.bad_since, self.bad_since_utc = now, now_utc
if self._held(r, now):
# EV-20 rig round 2 (PM): a reading missing for less than
# `stale_s` keeps the last trusted figure and decides nothing:
# no write, no pause, and it neither arms nor clears the stuck
# check. At `stale_s` the missing reading is taken as before.
self.held = True
self._status_edge(now, now_utc)
return
self.held = False
self.reading = r
self.obs_at = now
self._corr_note(r, now)
@@ -757,6 +769,13 @@ class CarTracker:
self._timers(r, now)
self._status_edge(now, now_utc)
def _held(self, r, now: float) -> bool:
"""Is this missing reading a short gap behind a usable one?"""
last = self.reading
return (not r.available and last is not None and last.available
and self.last_ok is not None
and now - self.last_ok < self.stale_s)
# -- reachability ----------------------------------------------------------
def unreachable(self, now: float) -> bool:
return self.bad_since is not None and now - self.bad_since >= UNREACHABLE_S
+18 -1
View File
@@ -368,6 +368,11 @@ class CarMixin:
cycle's read did) and writes only through `carmode`'s writers."""
if not self.charger.configured():
return
if self.car.held:
# EV-20 rig round 2 (PM): the charger missed a read for less than
# `stale_input_s`; the last trusted figure stands and nothing is
# decided or written from the gap.
return
now = self.car_now()
if self.car_mode != carmode.SOLAR:
await self.car_writer.step(
@@ -452,7 +457,19 @@ class CarMixin:
hold=hold, auto=ph not in ("1", "3"),
start_s=60.0 * carmode.solar_option(o, "ev_start_min"),
pause_s=60.0 * carmode.solar_option(o, "ev_pause_min"),
spare_w=spare, room_w=room, margin_w=margin, first=self.car_first)
spare_w=spare, room_w=room, margin_w=margin, first=self.car_first,
unknown_s=self._car_meter_over_s() if spare is None else 0.0)
def _car_meter_over_s(self) -> float:
"""EV-20 rig round 2 (PM): on `ha_signed`, how far the meter's age is
past `meter_max_age_s`, so Solar's pause comes at that age +
`ev_pause_min` (checked every cycle), not a cycle or two later."""
if not self.p1_enabled \
or str(self.o.get("meter_source") or "") != "ha_signed":
return 0.0
age = self.p1.age_s()
bound = float(self.o.get("meter_max_age_s", 30) or 30)
return 0.0 if age is None else max(0.0, age - bound)
def _car_sun_tick(self, mono) -> None:
"""Solar kWh: per cycle, in Solar only, the car's power up to the sun