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:
+51
View File
@@ -41,6 +41,9 @@ RISE_STILL_W = 50.0
# charger did not take (D3), so the next start can take its notice down.
CAR_SUN_KEY = "car_sun"
CAR_RELEASE_KEY = "car_release_failed"
# C1 (SPIKE-05): an own 0 A of Solar's is out and not read back yet, kept with
# the mode, so a start in Off after a power cut still writes it.
CAR_EXIT_KEY = "car_exit_0a_pending"
# EV-20 (D3): at shutdown in Solar the charger's 0 A waits at most this long,
# then the inverters are released whatever the charger did.
RELEASE_WAIT_S = 15.0
@@ -53,6 +56,13 @@ class CarMixin:
restart does with the mode. A site with no charger keeps defaults and
writes nothing."""
data = getattr(store, "data", None) or {}
# C1: the mode before the stop, and an exit 0 A still pending then.
stored = data.get(carmode.KEY_MODE)
self._car_stored_mode = stored if stored in carmode.MODES \
else carmode.OFF
self._car_exit_pending = bool(data.get(CAR_EXIT_KEY))
self._car_start_seen = False
self._car_start_warned = False
self.car_mode = carmode.start_mode(opts, data.get(carmode.KEY_MODE))
if carmode.start_mode(opts, carmode.MANUAL) == carmode.OFF \
and data.get(carmode.KEY_MODE) not in (None, carmode.OFF):
@@ -66,6 +76,9 @@ class CarMixin:
self.car_rev = 0
self.car_writer = carmode.ManualWriter()
self.car_solar = carmode.SolarWriter() # EV-20
self.car_solar.on_owed = self._car_owed
if self.car_mode == carmode.OFF and self._car_exit_pending:
self.car_solar.owe_start() # C1
first = data.get(carmode.KEY_FIRST)
self.car_first = first if first in carmode.FIRSTS \
else carmode.DEFAULT_FIRST
@@ -116,6 +129,40 @@ class CarMixin:
return (self.charger.configured()
and self.car_mode == carmode.MANUAL)
def _car_owed(self, pending) -> None:
"""C1: keep "an own 0 A is out, not read back" with the mode."""
pending = bool(pending)
if pending != self._car_exit_pending:
self._car_exit_pending = pending
self.store.set(CAR_EXIT_KEY, pending)
async def check_car_start(self) -> None:
"""C1: the first reading after a start that will not write (shadow,
control stopped) shows a current the add-on set before the stop
(Manual or Solar then): one warning, taken down once it is 0 A."""
r = self.car.reading
if r is None or not r.available or not self.charger.configured():
return
cur = r.allowed_a if r.allowed_a is not None else r.setpoint_a
if not self._car_start_seen:
self._car_start_seen = True
if self._car_stored_mode in (carmode.MANUAL, carmode.SOLAR) \
and not self.car_writing() and cur is not None \
and cur > carmode.TOL_A:
self._car_start_warned = True
_LOG.warning("The charger still has a current from before "
"the restart, and the add-on does not write "
"now: CHARGER_START_CURRENT.")
_LOG.debug("The charger shows %.0f A at the start.", cur)
await self.hass.call("persistent_notification", "create",
messages.car_start_current(
f"{cur:.0f}").data())
elif self._car_start_warned and cur is not None \
and cur <= carmode.TOL_A:
self._car_start_warned = False
await self.hass.call("persistent_notification", "dismiss",
messages.car_start_current_gone().data())
def car_solar_mode(self) -> bool:
"""EV-20: a charger is set up and the mode is Solar."""
ch = getattr(self, "charger", None)
@@ -331,6 +378,10 @@ class CarMixin:
status=self.car.status(now, True), clock=self.car_now)
w = self.car_solar
if self.car_mode == carmode.SOLAR or w.engaged:
# C6: one write clock: Manual's latest non-zero write counts.
w.other_at = max((t for kind, a, t, ok in self.car_writer.log
if kind == "current" and a > carmode.TOL_A),
default=None)
sun = None
if self.car_mode == carmode.SOLAR:
sun = getattr(self, "_car_sun_now", None) \
+1
View File
@@ -1070,6 +1070,7 @@ class CycleMixin:
await self.check_charger()
await self.check_car_over()
await self.check_car_release() # EV-20 (D3)
await self.check_car_start() # EV-20 (C1)
self.car_kick() # EV-04/20: in the background
await self.check_fixed_note()
+19
View File
@@ -191,6 +191,8 @@ T_CHARGER_UNREACH_NL = "Laadpaal onbereikbaar"
T_CAR_OVER = "Car over the peak limit"
T_CAR_OVER_NL = "Auto boven de piekgrens"
T_CAR_RELEASE = "Car may still be charging"
T_CAR_START = "Charger kept its current"
T_CAR_START_NL = "Laadpaal hield haar stroom"
T_CAR_RELEASE_NL = "Auto laadt mogelijk nog"
T_NO_PRICES = "No prices"
T_NO_PRICES_NL = "Prijzen ontbreken"
@@ -207,6 +209,7 @@ ID_NO_PRICES = "goodwe_no_prices"
ID_CHARGER_UNREACH = "goodwe_charger_unreachable"
ID_CAR_OVER = "goodwe_car_over"
ID_CAR_RELEASE = "goodwe_car_release"
ID_CAR_START = "goodwe_car_start_current"
# PRICE-01: an earlier build raised a card with this id. Nothing raises it now;
# the add-on only dismisses it at start.
OLD_FIXED_CARD_ID = "goodwe_fixed_tariff_unused"
@@ -554,6 +557,21 @@ def car_release_failed() -> Notice:
body_nl=f"{T_CAR_RELEASE_NL}. {nl}")
def car_start_current(a_text) -> Notice:
"""EV-20 (C1): the add-on starts without writing (shadow mode, control
stopped) and the charger still has a current the add-on set before the
stop. Taken down once the charger shows 0 A."""
return Notice(ID_CAR_START, WARNING, T_CAR_START,
f"Charger still at {a_text} A from before the restart.",
body_nl=f"{T_CAR_START_NL}. Laadpaal staat nog op {a_text} A "
f"van voor de herstart.")
def car_start_current_gone() -> Dismiss:
"""EV-20 (C1): takes the 'Charger kept its current' notice down."""
return Dismiss(ID_CAR_START)
def car_release_gone() -> Dismiss:
"""EV-20 (D3): takes the 'Car may still be charging' notice down."""
return Dismiss(ID_CAR_RELEASE)
@@ -1877,6 +1895,7 @@ def samples() -> list:
car_over("16"),
car_over_solar("8"),
car_release_failed(),
car_start_current("10"),
]