Compare commits

...
2 Commits
Author SHA1 Message Date
ems-agentandClaude 3682b0754b EV-56: a charger write that raises counts as a not-taken try
checks / unit (pull_request) Successful in 57m33s
infra-pin / fresh (pull_request) Successful in 2s
ManualWriter._write catches an Exception from drv.write_current (not CancelledError) and returns False, so every caller in Manual and Solar counts it as a refused try: RETRY_S spacing, MAX_TRIES, CHARGER_REFUSED. The tracker is not told (Q2). One ERROR record per raised value, armed again by another value, a taken write, a user change or the charger's return (Q1, G2). Shutdown writes (abandon, release) pass strict and keep base's behaviour (F3, H1, G3); the peak cut path keeps EV-54's (G1). test_ev13 T13: fails is 1 now (Q2). New test_ev56.py.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-11-30 18:52:11 +01:00
ems-agent 344c974f90 Merge pull request 'EV-54: a refused peak cut no longer stops Solar; tried again next quarter' (#280) from EV-54 into release/1.0
infra-pin / fresh (push) Successful in 2s
2026-11-30 09:14:11 +01:00
5 changed files with 1404 additions and 10 deletions
+1
View File
@@ -2,6 +2,7 @@
### Not in a release yet
- **A car current the add-on cannot send because of an error is no longer sent again every second.** It counts as a write the charger did not take: 3 tries a minute apart, then the add-on stops and warns CHARGER_REFUSED. The error is logged once per current ([[EV-56]]).
- **A peak cut the charger does not take no longer stops Solar.** After three refused tries in a 15-minute period, Solar goes on controlling the car and tries the cut again at the start of the next period while it is still needed. The warning now says "The charger did not take the peak cut, so the add-on tries again next quarter: CHARGER_REFUSED." ([[EV-54]]).
- **The add-on log now says when the add-on sets a new car current or the car mode changes.** One line each, for example "Car: set from 10 A to 6 A on 1 phase (Manual)." and "Car mode is now Manual." It names the reason: Manual, Solar, peak cut, start-up or shutdown. A refused write adds no such line, and nothing is written or timed differently ([[EV-52]]).
- **Solar now lowers the car first for the peak limit.** When the 15-minute period heads over the limit, Solar lowers the car before the batteries give more, and brings it back when the period allows. One grey note says "Solar lowered the car for the peak." A Solar car the add-on cannot lower (another writer, shadow mode, a stop) no longer hides a peak alarm. Manual and Off do not change. See "Car charger" in DOCS ([[EV-21]]).
@@ -0,0 +1,37 @@
# EV-56 — a charger write that raises is a not-taken try
`drv.write_current` raising (an HA call error, a binding or setup error, a bug)
left `ManualWriter._write` before any bookkeeping, so no caller counted it and
Manual and Solar sent the same write every cycle. The rules below are the PM
rulings Q1-Q4, F1, F3, G1-G3, H1, H3 and H4 (brief v6); the formal check is
reports/EV-56-formal-report.md.
## The rule, in plain words
- **A raise is a try the charger did not take**, on every path that writes a
current (the normal write, a phase change's 0 A and closing current, the
Off or shadow undo): the same RETRY_S spacing, MAX_TRIES cap, give-up and
CHARGER_REFUSED as a refusal, and the same writer state (`log` row,
`attempted_a`, a late accept). `ManualWriter._write` catches it and returns
False; the callers count it as before. Solar counts it in its own `_write`.
- **The tracker is not told** (Q2): no `note_write`, so no refusal window and
no stuck arming. The write's `end_write` (the mute) still runs.
- **One ERROR record per raised value** (Q1): "The car charger step failed",
with the traceback, at the first raise of a value; DEBUG on its retries. It
is armed again by another value written, a taken write, a user change and
the charger's return (G2), in `_rec_a`.
- **A peak cut try that raises** keeps EV-54's path: one DEBUG line, no record
(G1).
- **Shutdown is as before** (F3, H1, G3): `abandon` and `release` pass
`strict`, so a raise still leaves the write. Manual's give-back keeps its
CHARGER_RESTORE; Solar's release stops after 1 try with no cut standing and
keeps the cut path's 3 tries with one. No record at shutdown.
- **Cancel is not a raise**: only `Exception` is caught, never
`CancelledError`.
## Left as they were
The phase select (`write_phases`, Q4, EV-58), Solar's 4 fails for a refused
close (F1), Manual's up to 5 tries of a close value (H3, EV-59) and the cut
tries through a phase change (H4, EV-60). test_ev56.py T5b and T19b pin the
last two at base.
+50 -9
View File
@@ -148,6 +148,7 @@ class ManualWriter:
self._returned = False # ... and came back after being gone
self._r = None # the latest reading, for the phase count
self._late = None # (a, was, why, n) of a write not taken
self._rec_a = None # EV-56: the raised value already logged
# ------------------------------------------------------------------ user
def user_changed(self) -> None:
@@ -161,6 +162,7 @@ class ManualWriter:
self.phase_fails, self.phases_gave_up = 0, False
self.attempted_a = self.prior_a = None
self._late = None # EV-52: that request is not current now
self._rec_a = None # EV-56 (G2): a raise is logged again
# ------------------------------------------------------------------ step
async def step(self, drv, r, *, mode, want_a, want_phases, rev, clamp,
@@ -185,6 +187,7 @@ class ManualWriter:
self._seen = True
self.was_available = True
self.reapply = True # on return: only if it differs
self._rec_a = None # EV-56 (G2): logged again
cur = r.allowed_a if r.allowed_a is not None else r.setpoint_a
if self.seq is not None:
if self.seq["stage"] in ("zero", "select") \
@@ -320,31 +323,58 @@ class ManualWriter:
async def _write(self, drv, a, was, now, tracker, **kw) -> bool:
why = kw.pop("why", None) or self._why_default()
n = kw.pop("n", None)
# EV-56: a raise at shutdown is left to the caller (CHARGER_RESTORE).
strict = kw.pop("strict", False)
self._late = None
if self._rec_a is not None and abs(self._rec_a - float(a)) > TOL_A:
self._rec_a = None # EV-56 (G2): another value
tracker.begin_write() # EV-12: the read-back is ours
if float(a) > TOL_A:
# EV-20 C6, THE ONE WRITE CLOCK: every non-zero current either
# writer sends, whatever path it comes from, is stamped here (the
# one write_current call). Solar's 30 s gate reads this stamp.
self.nonzero_at = now
err = None
try:
# EV-20: `kw` is only Solar's shorter read-back wait at shutdown.
ok = await drv.write_current(a, **kw)
except Exception as e: # noqa: BLE001
if strict:
raise
ok, err = False, e
finally:
self._stamp(now)
tracker.end_write(self.last_done)
if err is not None:
self._raised(err, a, was, now, why, n)
return False
tracker.note_write(now, was, a, ok, getattr(drv, "polls", ()))
tracker.end_write(self.last_done)
self.log.append(("current", a, now, ok))
if ok:
self.last_a = a
self.attempted_a = self.prior_a = None
self._rec_a = None # EV-56 (G2): a taken write
self._log_set(a, was, why, n)
else:
self.attempted_a, self.prior_a = a, was
self._late = (a, was, why, n) # logged if it is adopted later
return ok
def _raised(self, err, a, was, now, why, n) -> None:
"""EV-56: a write that raised (an HA call error, a setup error, a bug)
is a try the charger did not take, counted by the caller as a refusal
is. It is no charger answer, so the tracker is not told (Q2). Its
ERROR record, with the traceback, comes once per raised value (Q1)."""
self.log.append(("current", a, now, False))
self.attempted_a, self.prior_a = a, was
self._late = (a, was, why, n) # logged if it is adopted later
if self._rec_a is None:
self._rec_a = float(a)
_LOG.error("The car charger step failed", exc_info=err)
else:
_LOG.debug("The car charger write failed again: %s", err)
def _stamp(self, now) -> None:
self.last_done = (self._clock or (lambda: now))()
@@ -395,7 +425,8 @@ class ManualWriter:
a = None if q is None else self._restore_a(q.get("prev"), clamp)
if a is not None:
self._clock = self._clock or (lambda: now)
await self._write(drv, a, 0.0, now, tracker, why="shutdown")
await self._write(drv, a, 0.0, now, tracker, why="shutdown",
strict=True)
async def _advance(self, drv, r, cur, now, tracker, want_a, clamp, rev):
q = self.seq
@@ -972,6 +1003,7 @@ class SolarWriter(ManualWriter):
the write goes out, so a write cancelled while it waits for its
read-back is never trusted (`live`)."""
prev = self.sent_a
strict = kw.pop("strict", False) # EV-56: `release` (H1)
why = kw.get("why")
if why is None:
# EV-52: the 0 A the start caused is `start-up`, else Solar's own.
@@ -998,15 +1030,22 @@ class SolarWriter(ManualWriter):
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)
ok = await super()._write(drv, a, was, now, tracker,
strict=True, **kw)
except Exception as e: # noqa: BLE001
if not cut_try:
raise
# EV-54 (T15): a cut write that raises is a refused cut try, so it
# is spaced and capped like one, not tried once per cycle.
_LOG.debug("The peak cut write failed: %s", e)
self.log.append(("current", a, now, False))
self.attempted_a, self.prior_a = a, was
if strict:
raise # EV-56 (H1): shutdown as before
# EV-56: a try the charger did not take, counted below as a
# refusal is; the tracker is not told (Q2).
self._raised(e, a, was, now, why, kw.get("n"))
else:
# EV-54 (T15): a cut write that raises is a refused cut try,
# so it is spaced and capped like one, not tried once per
# cycle.
_LOG.debug("The peak cut write failed: %s", e)
self.log.append(("current", a, now, False))
self.attempted_a, self.prior_a = a, was
ok = False
finally:
if zero:
@@ -1353,6 +1392,7 @@ class SolarWriter(ManualWriter):
self.fresh_start = self.restart = True
self.mismatch_since = None
self.last_a = self.attempted_a = self.prior_a = None
self._rec_a = None # EV-56 (G2): logged again
cur = r.allowed_a if r.allowed_a is not None else r.setpoint_a
stuck = bool(tracker is not None and tracker.stuck(now))
if not self.taken and self.sent_a is not None and not stuck \
@@ -1578,7 +1618,8 @@ class SolarWriter(ManualWriter):
if wait > 0:
await sleep(wait)
if await self._write(drv, 0.0, cur, clock(), tracker,
took_s=RELEASE_TOOK_S, why="shutdown"):
took_s=RELEASE_TOOK_S, why="shutdown",
strict=True):
self.released = True
return True
self.released = False
+1 -1
View File
@@ -802,7 +802,7 @@ for exc in (RuntimeError("the link broke"), hass.ReadOnly("read only")):
"never armed, no window left, no refusal counted, the mute set, "
f"the step error logged once ({len(errs)})",
never_stuck(tr) and pend(w.c.car) is None
and w.c.car_writer.fails == 0 and w.c.car.mute_until > 0
and w.c.car_writer.fails == 1 and w.c.car.mute_until > 0
and len(errs) == 1)
File diff suppressed because it is too large Load Diff