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
+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) \