EV-20: SPIKE-05 decisions C1, C6, C9 (brief v5) with rows for C1, C5, C6, C8, C9
checks / unit (pull_request) Successful in 34m42s
infra-pin / fresh (pull_request) Successful in 2s

C1: an own 0 A not yet read back is kept with the mode; a start in Off with
it writes the 0 A (retried), without it nothing; a start that will not write
warns once when the charger still has the add-on's current. C6: Solar's 30 s
gate also counts from Manual's latest write. C9: an exit also owes its 0 A
when the read-back shows Solar's own value. Rows for C5 and C8 too.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VSY9UpTaUYnjJF5oVtbM1w
This commit is contained in:
Claude
2026-11-22 21:33:28 +01:00
parent d18ed56fad
commit e0138a2ae5
8 changed files with 282 additions and 5 deletions
+46 -3
View File
@@ -515,6 +515,7 @@ class SolarPlan:
self.why = why
self.target_w = None
self._before = None # the state before a phase change
self.ext_at = None # C6: Manual's latest non-zero write
def pause(self, why="paused"):
self.a = 0.0
@@ -524,7 +525,9 @@ class SolarPlan:
self.why = why
def _gate(self, now) -> bool:
return self.set_at is None or now - self.set_at >= SOLAR_WRITE_S
"""30 s since the latest non-zero write, Solar's or (C6) Manual's."""
return all(t is None or now - t >= SOLAR_WRITE_S
for t in (self.set_at, self.ext_at))
def _set(self, a, now, n=None):
if n is not None and n != self.n:
@@ -584,7 +587,7 @@ class SolarPlan:
if self.ok_since is None:
self.ok_since = now
self.why = "start"
if now - self.ok_since >= start_s \
if now - self.ok_since >= start_s and self._gate(now) \
and (n0 == self.n or gap_ok):
a = amps_for(target_w, n0, clamp)
if a is not None and a >= CH.MIN_A:
@@ -691,6 +694,19 @@ class SolarWriter(ManualWriter):
self._would_switch = None # ... and when it last changed them
self.released = None # D3: True / False once shutdown tried
self.mode_was = None # the mode of the previous step
self.start_owed = False # C1: a start in Off with a 0 A pending
self.other_at = None # C6: Manual's latest non-zero write
self.on_owed = None # C1: told when an own 0 A is out / back
def owe_start(self) -> None:
"""C1: the add-on starts in Off while an exit 0 A of its own was still
pending at the stop: the current the charger shows is the add-on's,
so the 0 A is owed (once it may write), retried by the exit rule."""
self.start_owed = self.engaged = True
def _owed(self, pending: bool) -> None:
if self.on_owed is not None:
self.on_owed(pending)
# ------------------------------------------------------------- state
@property
@@ -735,6 +751,7 @@ class SolarWriter(ManualWriter):
zero = float(a) <= TOL_A
if zero:
self.zero_at = self.zero_sent_at = now
self._owed(True) # C1: kept with the mode until back
try:
ok = await super()._write(drv, a, was, now, tracker, **kw)
finally:
@@ -743,6 +760,8 @@ class SolarWriter(ManualWriter):
if ok:
self.taken = True
self.fails, self.fail_at, self.gave_up = 0, None, False
if zero:
self._owed(False)
else:
self._failed(now)
return ok
@@ -758,6 +777,8 @@ class SolarWriter(ManualWriter):
def _adopt(self, cur) -> None:
"""The read-back shows what Solar sent: taken, however late."""
if self.sent_a is not None and self.sent_a <= TOL_A:
self._owed(False)
self.taken = True
self.last_a = cur
self.attempted_a = self.prior_a = None
@@ -787,11 +808,23 @@ class SolarWriter(ManualWriter):
return
await self._write(drv, want, cur, now, tracker)
def _own_readback(self, cur) -> bool:
"""C9: does the read-back show a current of Solar's own (sent,
confirmed, tried, or shown when a try was refused)?"""
if cur is None or cur <= TOL_A:
return False
return any(k is not None and k > TOL_A and abs(cur - k) <= TOL_A
for k in (self.sent_a, self.last_a, self.attempted_a,
self.prior_a))
async def _zero(self, drv, cur, now, tracker, stuck=False) -> None:
"""A way out: 0 A while Solar's own current may stand, never over
"""A way out: 0 A while Solar's own current may stand (its own
bookkeeping, or C9 the read-back showing its value), never over
another writer's hold."""
self.seq = None
self.plan.end_switch(False)
if not self.live and self._own_readback(cur) and not stuck:
self.taken = False # C9: a 0 A is owed
if self.live and not self.hold:
await self._put(drv, 0.0, cur, now, tracker, stuck)
@@ -830,6 +863,7 @@ class SolarWriter(ManualWriter):
def _leave(self) -> None:
"""Solar is no longer the mode and owes nothing."""
self.engaged, self.seq, self.would = False, None, None
self.start_owed = False
self.out, self.fault = False, None
self.restart = True
self.mismatch_since = None
@@ -840,6 +874,7 @@ class SolarWriter(ManualWriter):
>= PHASE_GAP_S
def _plan_step(self, sun, now, clamp, n_now, gap_ok) -> None:
self.plan.ext_at = self.other_at
self.plan.step(
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,
@@ -932,6 +967,14 @@ class SolarWriter(ManualWriter):
self._mark(r, now)
if mode != SOLAR:
self.would = None
if mode == OFF and self.start_owed:
if not writing:
return # C1: waits; the start warning says so
self.start_owed = False
if cur is not None and cur > TOL_A and not self.hold:
self.sent_a, self.taken = cur, True # ours, from before
else:
self._owed(False)
if mode == OFF: # 0 A while owed, then nothing
await self._zero(drv, cur, now, tracker, stuck)
if self.live and not self.hold: