EV-05 round 3: a refused way-out 0 A is tried again; one cut per excess
Review of 17a7b29:
- Critical: every way out of Solar (Off, Stop, shadow, safety stop, charger
error, stuck reading, no car) now owes a 0 A until the charger takes it:
tried again 60 s apart, 3 times (EV-04's rule), then the gave-up row and
CHARGER_REFUSED; never over another writer. Shutdown does not trust last_a
while a write of ours is unconfirmed. The card no longer says paused while
the 0 A is not taken.
- Major: an excess episode is taken off the car once, measured from the car's
power when it began, until the car shows it and 15 s more.
Tests: refused-then-accepted 0 A for each exit, a 0 A never taken, shutdown
during a start write's read-back, a cut from 16 A with a slow car; the fuzz
checks refused exits of every kind (N9).
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -58,6 +58,22 @@ inputs (`car_sun_inputs`) and runs the writer in the same background task.
|
||||
- **Shadow mode** runs the plan without writing, so the card says what it would
|
||||
set; the charger got its one 0 A when shadow mode came on.
|
||||
|
||||
## Round 3 (review of 17a7b29)
|
||||
|
||||
- **A way-out 0 A is written until the charger takes it** (`SolarWriter.
|
||||
_exit_zero`): Off, Stop, shadow, a safety stop, a charger error, a stuck
|
||||
reading and no car each owe a 0 A; one that is not taken is tried again by
|
||||
EV-04's rule (`RETRY_S` 60 s apart, `MAX_TRIES` 3), then the gave-up row and
|
||||
`CHARGER_REFUSED`. Once taken, or once the charger shows 0 A, nothing more.
|
||||
Never over another writer. A stuck reading cannot confirm a write, so there
|
||||
only a taken write counts (up to 3 tries). At shutdown there is one try, and
|
||||
a write of ours not yet confirmed (cancelled during its read-back) means the
|
||||
current is unknown, so the 0 A is written.
|
||||
- **One excess, one cut** (`SolarPlan.ep`): an excess episode is measured from
|
||||
the car's power when it began, so the same excess is not taken off again
|
||||
while the meter still shows the old power. A new cut needs the car to show
|
||||
the lower power and `CUT_SETTLE_S` (15 s) more for the meter.
|
||||
|
||||
## Solar kWh
|
||||
|
||||
Per cycle in Solar: `min(car power, max(0, spare - room))` Batteries first,
|
||||
|
||||
@@ -3356,10 +3356,13 @@ Both apply at once, with no restart.
|
||||
catch does not pause the car. With every battery at its cut-out level, or
|
||||
in the last 2 minutes of the 15-minute period, it cuts at once. A Solar
|
||||
charge never sets the month's peak.
|
||||
- **Every way out of Solar leaves the charger at 0 A**, written once: a stop or
|
||||
- **Every way out of Solar leaves the charger at 0 A**: a stop or
|
||||
restart of the add-on (before the inverters go to 0 W), stopping control, a
|
||||
safety stop, shadow mode turned on, choosing Off, an unplugged car, a charger
|
||||
error or a stuck reading. After the charger or Home Assistant was away, the
|
||||
error or a stuck reading. If the charger does not take the 0 A, the add-on
|
||||
tries again a minute later, three times, then shows *Charger did not take
|
||||
it* and a warning. Once taken, nothing more is written. After the charger
|
||||
or Home Assistant was away, the
|
||||
add-on first sets 0 A, then starts again by the rules. A meter that stops
|
||||
gives a hold for *Pause after*, then 0 A. Choosing Manual leaves it to Manual.
|
||||
- Another writer stops the add-on's writes after 30 seconds, with an amber row
|
||||
|
||||
@@ -410,6 +410,12 @@ UP_W, UP_S = 4500.0, 180.0 # auto phases: to 3 at this for this long
|
||||
DOWN_W, DOWN_S = 4000.0, 300.0 # ... back to 1 under this for this long
|
||||
ONE_PHASE_S = 10.0 # one phase drawing while 3 are allowed this long
|
||||
ONE_PHASE_MIN_W = 500.0 # ... with the car drawing at least this
|
||||
# EV-05 round 3: one excess episode is taken off the car ONCE, measured from
|
||||
# the car's power when it began, until the car shows the lower power
|
||||
# (within CUT_SEEN_W) and then CUT_SETTLE_S more for the meter to see it (a
|
||||
# DSMR4 telegram is 10 s). Only then can a still standing excess cut again.
|
||||
CUT_SEEN_W = 100.0
|
||||
CUT_SETTLE_S = 15.0
|
||||
|
||||
|
||||
def _num(v):
|
||||
@@ -495,6 +501,7 @@ class SolarPlan:
|
||||
self.unknown_since = None # the spare cannot be measured, since
|
||||
self.up_since = self.down_since = None
|
||||
self.cap_a = self.cap_key = None # the peak cut, for this period
|
||||
self.ep = None # the cut episode: [base W, target W, seen]
|
||||
self.why = self.pause_why = why
|
||||
self.target_w = None
|
||||
|
||||
@@ -531,14 +538,27 @@ class SolarPlan:
|
||||
self.target_w = target_w
|
||||
# The peak guard's excess comes off the car first, at once (no 30 s
|
||||
# rule, no hold). Nothing starts while the period heads over the aim.
|
||||
if not (cut_w and cut_w > 0.0):
|
||||
self.ep = None
|
||||
if cut_w and cut_w > 0.0:
|
||||
self.ok_since = None
|
||||
if self.a > 0.0:
|
||||
base = self.a * VOLTS * n_calc
|
||||
cw = _num(car_w)
|
||||
if cw is not None:
|
||||
base = min(base, cw)
|
||||
new = amps_for(base - float(cut_w), n_calc, clamp)
|
||||
ep = self.ep
|
||||
if ep is not None and ep[2] is None \
|
||||
and (cw is None or cw <= ep[1] + CUT_SEEN_W):
|
||||
ep[2] = now # the car shows the cut
|
||||
if ep is None or (ep[2] is not None
|
||||
and now - ep[2] >= CUT_SETTLE_S):
|
||||
base = self.a * VOLTS * n_calc
|
||||
if cw is not None:
|
||||
base = min(base, cw)
|
||||
ep = self.ep = [base, base, None]
|
||||
# Measured from the episode's start, so the same excess is not
|
||||
# taken off again while the meter still shows the old power.
|
||||
new = amps_for(ep[0] - float(cut_w), n_calc, clamp)
|
||||
if new is not None:
|
||||
ep[1] = min(ep[1], new * VOLTS * n_calc)
|
||||
if new is None or new < MIN_A:
|
||||
self._pause("cut")
|
||||
elif new < self.a:
|
||||
@@ -634,18 +654,21 @@ class SolarPlan:
|
||||
class SolarWriter(ManualWriter):
|
||||
"""What Solar does to the charger, one `step()` per cycle. It shares
|
||||
ManualWriter's write, phase sequence and other-writer watch; what differs
|
||||
is that every way out ends at 0 A, written once, and that an interrupted
|
||||
phase change is never undone to the old current."""
|
||||
is that every way out ends at 0 A, and that an interrupted phase change is
|
||||
never undone to the old current. The way-out 0 A is written until the
|
||||
charger takes it (EV-04's rule: `RETRY_S` apart, `MAX_TRIES`, then the
|
||||
gave-up row and warning), and once taken nothing more."""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.plan = SolarPlan()
|
||||
self.engaged = False # Solar has run since it was chosen
|
||||
self.reinit = True # start again from 0 A and the start rule
|
||||
self.out = False # not writing: the 0 A has been tried
|
||||
self.stand = False # no car: the standing 0 A has been tried
|
||||
self.out = False # not writing (shadow, Stop, safety stop)
|
||||
self.zero_for = None # the way out a 0 A is owed for
|
||||
self.zero_ok = False # ... and the charger has taken it
|
||||
self.inflight = None # a current being written, not yet back
|
||||
self.fault = None # "error" | "stuck" while it holds
|
||||
self.fault_done = False
|
||||
self.warned = False # the charger error warning, once
|
||||
self.single = False # a one-phase car on a 3-phase allowance
|
||||
self._one_since = None
|
||||
@@ -699,19 +722,55 @@ class SolarWriter(ManualWriter):
|
||||
super().user_changed()
|
||||
self.sent_a = None
|
||||
|
||||
async def _zero_once(self, drv, cur, now, tracker, force=False) -> None:
|
||||
"""One try of 0 A on the way out. Never over another writer, and not
|
||||
when the charger already shows 0 A (unless the reading is stuck, so
|
||||
its 0 A means nothing: `force`)."""
|
||||
if self.hold or (not force and cur is not None and cur <= TOL_A):
|
||||
async def _write(self, drv, a, was, now, tracker) -> bool:
|
||||
self.inflight = a # cleared only when the write returns
|
||||
ok = await super()._write(drv, a, was, now, tracker)
|
||||
self.inflight = None
|
||||
return ok
|
||||
|
||||
def _zero_done(self) -> None:
|
||||
"""No way out is under way any more: forget its 0 A and its tries."""
|
||||
if self.zero_for is not None:
|
||||
self.zero_for, self.zero_ok = None, False
|
||||
self.fails, self.fail_at, self.gave_up = 0, None, False
|
||||
|
||||
async def _exit_zero(self, why, drv, cur, now, tracker,
|
||||
force=False) -> None:
|
||||
"""0 A on the way out (`why`), until the charger takes it: a write
|
||||
that is not taken is tried again `RETRY_S` later, `MAX_TRIES` times,
|
||||
then the gave-up row and warning. Once taken, or once the charger
|
||||
shows 0 A, nothing more. Never over another writer. `force`: the
|
||||
reading is stuck, so its 0 A means nothing; only a taken write
|
||||
counts."""
|
||||
if self.zero_for != why:
|
||||
self.zero_for, self.zero_ok = why, False
|
||||
self.fails, self.fail_at, self.gave_up = 0, None, False
|
||||
if self.zero_ok or self.hold:
|
||||
return
|
||||
if not force and cur is not None and cur <= TOL_A:
|
||||
self.zero_ok = True
|
||||
self.fails, self.fail_at = 0, None
|
||||
return
|
||||
if self.gave_up or (self.fail_at is not None
|
||||
and now - self.fail_at < RETRY_S):
|
||||
return
|
||||
self.zero_at, self.sent_a = now, 0.0
|
||||
await self._write(drv, 0.0, cur, now, tracker)
|
||||
if await self._write(drv, 0.0, cur, now, tracker):
|
||||
self.zero_ok = True
|
||||
self.fails, self.fail_at = 0, None
|
||||
else:
|
||||
self._failed(now)
|
||||
|
||||
@property
|
||||
def zero_owed(self) -> bool:
|
||||
"""A way-out 0 A the charger has not taken yet (for the card)."""
|
||||
return self.zero_for is not None and not self.zero_ok and not self.hold
|
||||
|
||||
def _leave(self) -> None:
|
||||
self.engaged, self.seq, self.would = False, None, None
|
||||
self.out = self.stand = False
|
||||
self.fault, self.fault_done = None, False
|
||||
self.out = False
|
||||
self._zero_done()
|
||||
self.fault = None
|
||||
self.reinit = True
|
||||
self.sent_a = None
|
||||
self.plan.reset(self.plan.n)
|
||||
@@ -748,21 +807,22 @@ class SolarWriter(ManualWriter):
|
||||
self.would = None
|
||||
if not self.engaged:
|
||||
return
|
||||
if mode != MANUAL: # Off: 0 A once, then nothing
|
||||
if mode != MANUAL: # Off: 0 A until taken, then nothing
|
||||
self.seq = None
|
||||
await self._zero_once(drv, cur, now, tracker)
|
||||
await self._exit_zero("off", drv, cur, now, tracker)
|
||||
if self.zero_owed:
|
||||
return # tried again next cycle (or gave up)
|
||||
self._leave() # Manual writes its own current
|
||||
return
|
||||
self.engaged = True
|
||||
if sun is None:
|
||||
return
|
||||
if not writing:
|
||||
# Shadow, Stop, a safety stop, stopping: 0 A once, then nothing.
|
||||
# The plan goes on, so the card says what it would set.
|
||||
# Shadow, Stop, a safety stop, stopping: 0 A until taken, then
|
||||
# nothing. The plan goes on, so the card says what it would set.
|
||||
self.seq = None
|
||||
if not self.out:
|
||||
self.out = True
|
||||
await self._zero_once(drv, cur, now, tracker)
|
||||
self.out = True
|
||||
await self._exit_zero("out", drv, cur, now, tracker)
|
||||
self._plan_step(sun, now, clamp)
|
||||
self.would = (self.amps_out(clamp), self.n_calc)
|
||||
self.reinit = True
|
||||
@@ -776,31 +836,27 @@ class SolarWriter(ManualWriter):
|
||||
# 0 A once, then no write until it clears; then the start rule.
|
||||
self.seq = None
|
||||
if self.fault != fault:
|
||||
self.fault, self.fault_done = fault, False
|
||||
self.fault = fault
|
||||
if fault == "error" and not self.warned:
|
||||
self.warned = True
|
||||
_LOG.warning("The charger reports an error, so the add-on "
|
||||
"sets the car to 0 A: CHARGER_ERROR.")
|
||||
if not self.fault_done:
|
||||
self.fault_done = True
|
||||
await self._zero_once(drv, cur, now, tracker,
|
||||
force=fault == "stuck")
|
||||
await self._exit_zero(fault, drv, cur, now, tracker,
|
||||
force=fault == "stuck")
|
||||
self.plan.reset(self.plan.n, why=fault)
|
||||
self.reinit = True
|
||||
return
|
||||
if self.fault is not None:
|
||||
self.fault, self.fault_done = None, False
|
||||
self.fault = None
|
||||
self.warned = False
|
||||
if r.state == "A" or status == CH.NONE_:
|
||||
# No car: the standing current is 0 A, written once.
|
||||
# No car: the standing current is 0 A, written until taken.
|
||||
self.seq = None
|
||||
if not self.stand:
|
||||
self.stand = True
|
||||
await self._zero_once(drv, cur, now, tracker)
|
||||
await self._exit_zero("none", drv, cur, now, tracker)
|
||||
self.plan.reset(self.plan.n, why="none")
|
||||
self.reinit = False
|
||||
return
|
||||
self.stand = False
|
||||
self._zero_done() # no way out under way now
|
||||
if self.reinit:
|
||||
self.reinit = False
|
||||
self.seq = None
|
||||
@@ -864,17 +920,26 @@ class SolarWriter(ManualWriter):
|
||||
self._failed(now)
|
||||
|
||||
async def release(self, drv, r, now, tracker) -> None:
|
||||
"""The add-on stops in Solar: 0 A, once, before the inverters go to
|
||||
0 W. A phase change in the middle is not undone to the old current."""
|
||||
"""The add-on stops in Solar: 0 A before the inverters go to 0 W, one
|
||||
try (it is stopping). A phase change in the middle is not undone to
|
||||
the old current. A write of ours that is not confirmed (cancelled
|
||||
while it waited for its read-back) means the charger's current is not
|
||||
known, so the 0 A is written."""
|
||||
self.seq = None
|
||||
if r is not None and r.available:
|
||||
cur = r.allowed_a if r.allowed_a is not None else r.setpoint_a
|
||||
else:
|
||||
cur = None
|
||||
if self.last_done is not None and tracker is not None \
|
||||
if self.inflight is not None or self.attempted_a is not None:
|
||||
cur = None # a write of ours is not confirmed: assume nothing
|
||||
elif self.last_done is not None and tracker is not None \
|
||||
and tracker.obs_at is not None \
|
||||
and tracker.obs_at <= self.last_done:
|
||||
cur = self.last_a # the reading predates our own write
|
||||
self._clock = self._clock or (lambda: now)
|
||||
await self._zero_once(drv, cur, now, tracker)
|
||||
self.inflight = None
|
||||
# One try: the add-on is stopping, bounded by `ctl_car.RELEASE_WAIT_S`.
|
||||
if not self.hold and not (cur is not None and cur <= TOL_A):
|
||||
self.zero_at, self.sent_a = now, 0.0
|
||||
await self._write(drv, 0.0, cur, now, tracker)
|
||||
self.out = True
|
||||
|
||||
@@ -231,6 +231,10 @@ class StatusMixin:
|
||||
if w.phases_gave_up:
|
||||
out.append({"ok": False, "warn": True, "id": "charger_phases",
|
||||
"text": messages.row_charger_phases()})
|
||||
elif self.car_mode != "manual" and sw.engaged and sw.gave_up:
|
||||
# EV-05: Solar to Off whose 0 A the charger never took.
|
||||
out.append({"ok": False, "warn": True, "id": "charger_refused",
|
||||
"text": messages.row_charger_refused()})
|
||||
elif self.car.other_writer(datetime.now(timezone.utc)):
|
||||
out.append({"ok": True, "warn": True, "id": "charger_writer",
|
||||
"text": messages.row_charger_writer()})
|
||||
|
||||
@@ -1345,6 +1345,10 @@ def _car_solar_why(c, key):
|
||||
o = getattr(c, "o", {}) or {}
|
||||
if w.other:
|
||||
return _t("car.why.solar_other")
|
||||
if w.zero_owed:
|
||||
# EV-05 round 3: the way-out 0 A is not taken yet; never "paused".
|
||||
return _t("car.why.solar_zero_failed" if w.gave_up
|
||||
else "car.why.solar_zeroing")
|
||||
if c.shadow:
|
||||
a, n = w.would if w.would is not None else (0.0, p.n)
|
||||
if a and a >= 6:
|
||||
|
||||
@@ -343,7 +343,9 @@
|
||||
"solar_stopped": "Control is stopped, so the add-on paused the car.",
|
||||
"solar_error": "The charger reports an error, so the add-on paused the car.",
|
||||
"solar_stuck": "The charger reading may be stuck, so the add-on paused the car.",
|
||||
"solar_other": "Something else changes the charger, so the add-on leaves it alone."
|
||||
"solar_other": "Something else changes the charger, so the add-on leaves it alone.",
|
||||
"solar_zeroing": "The charger has not taken 0 A yet. The add-on tries again.",
|
||||
"solar_zero_failed": "The charger did not take 0 A. Check it at the charger itself."
|
||||
}
|
||||
},
|
||||
"peak": {
|
||||
|
||||
@@ -297,7 +297,9 @@
|
||||
"solar_stopped": "De regeling is gestopt, dus de add-on pauzeert de auto.",
|
||||
"solar_error": "De laadpaal meldt een fout, dus de add-on pauzeert de auto.",
|
||||
"solar_stuck": "De laadpaal meet mogelijk niet meer, dus de add-on pauzeert de auto.",
|
||||
"solar_other": "Iets anders wijzigt de laadpaal, dus de add-on laat haar met rust."
|
||||
"solar_other": "Iets anders wijzigt de laadpaal, dus de add-on laat haar met rust.",
|
||||
"solar_zeroing": "De laadpaal nam 0 A nog niet aan. De add-on probeert opnieuw.",
|
||||
"solar_zero_failed": "De laadpaal nam 0 A niet aan. Controleer ze aan de laadpaal zelf."
|
||||
}
|
||||
},
|
||||
"peak": {
|
||||
|
||||
@@ -997,7 +997,7 @@ fz = st31.get("fz", 0)
|
||||
check(f"T31: a stuck reading after a write that moved the setpoint: 0 A once "
|
||||
f"about 60 s after that write (+10 s read-back), the amber row, no "
|
||||
f"write until a reading moves, then the start rule ({w31}, frozen at "
|
||||
f"{fz})", [v for t, v in w31 if t < fz + 400].count(0.0) == 1
|
||||
f"{fz})", 1 <= [v for t, v in w31 if t < fz + 400].count(0.0) <= 3
|
||||
and any(v == 0.0 and 60 <= t - w31[0][0] <= 75 for t, v in w31)
|
||||
and "charger_stuck" in st31.get("rows", [])
|
||||
and all(t >= fz + 400 + 120 for t, v in w31 if v > 0 and t > fz + 100))
|
||||
@@ -1554,6 +1554,142 @@ check(f"T52: in Solar the House tile and the house profile still leave the car "
|
||||
f"out: car_term gives the car's own power ({_c52.car_term()})",
|
||||
_c52.car_term()[1] is False and _c52.car_term()[0] > 2000)
|
||||
|
||||
# =========================================================================== #
|
||||
print("\nROUND 3. A REFUSED WAY-OUT 0 A IS TRIED AGAIN; ONE CUT PER EXCESS (N9)")
|
||||
# =========================================================================== #
|
||||
|
||||
|
||||
def refusing(kind):
|
||||
def f(p, c):
|
||||
p.ch.refuse = kind
|
||||
return f
|
||||
|
||||
|
||||
def zlog(r, t0):
|
||||
"""(second, A, taken) of each current write of the Solar writer."""
|
||||
return [(round(t), v, ok) for k, v, t, ok in r["c"].car_solar.log
|
||||
if k == "current" and t >= t0]
|
||||
|
||||
|
||||
def _err(p, c):
|
||||
p.ch.error = "12: Socket fault"
|
||||
|
||||
|
||||
EXITS3 = (("Stop", act("auto_toggle", None), {"shadow_mode": "off"}),
|
||||
("Off", act("car_mode", "off"), {}),
|
||||
("shadow on", lambda p, c: c.o.__setitem__("shadow_mode", "on"),
|
||||
{}),
|
||||
("safety stop", lambda p, c: setattr(c.circ_wd, "tripped", True),
|
||||
{}),
|
||||
("charger error", _err, {}),
|
||||
("unplug", lambda p, c: p.ch.unplug(), {}))
|
||||
for name, trig, opts3 in EXITS3:
|
||||
for kind in ("error", "ignore"):
|
||||
r3 = solar_exit(trig, dur=600, opts=opts3, events={
|
||||
299: refusing(kind), 305: refusing(None)})
|
||||
z3 = zlog(r3, 299)
|
||||
taken = [x for x in z3 if x[1] == 0.0 and x[2]]
|
||||
check(f"R3/N9 {name}, the first 0 A refused ({kind}): tried again "
|
||||
f"60 s later and taken once, the charger ends at 0 A ({z3})",
|
||||
z3 and z3[0][1] == 0.0 and z3[0][0] <= 302 and not z3[0][2]
|
||||
and len(taken) == 1 and taken[0][0] - z3[0][0] >= 60
|
||||
and taken[0][0] - z3[0][0] <= 75 and len(z3) <= 3
|
||||
and not [x for x in z3 if x[1] > 0]
|
||||
and r3["sim"].setpoint_a == 0.0 and r3["sim"].power_w == 0.0)
|
||||
n_ref3 = LOG.count("WARNING", "CHARGER_REFUSED")
|
||||
st3 = {}
|
||||
|
||||
|
||||
def _st3(p, c, t):
|
||||
if t == 599:
|
||||
st3["rows"] = [x["id"] for x in c.checks()]
|
||||
st3["why"] = homeview.car_block(c, None)["why"]
|
||||
|
||||
|
||||
r3g = solar_exit(act("auto_toggle", None), dur=600,
|
||||
opts={"shadow_mode": "off"},
|
||||
events={299: refusing("error")}, on_cycle=_st3)
|
||||
z3g = zlog(r3g, 299)
|
||||
check(f"R3: a 0 A the charger never takes: 3 tries 60 s apart, then the "
|
||||
f"gave-up row and one warning, and the card does not say paused "
|
||||
f"({z3g}, {st3.get('why')!r})",
|
||||
[x[1] for x in z3g] == [0.0, 0.0, 0.0]
|
||||
and all(b[0] - a[0] >= 60 for a, b in zip(z3g, z3g[1:]))
|
||||
and "charger_refused" in st3.get("rows", [])
|
||||
and LOG.count("WARNING", "CHARGER_REFUSED") - n_ref3 == 1
|
||||
and "paused" not in st3.get("why", "paused")
|
||||
and r3g["c"].car_solar.gave_up)
|
||||
r3o = solar_exit(act("car_mode", "off"), dur=600,
|
||||
events={299: refusing("error")}, on_cycle=_st3)
|
||||
check(f"R3: the same after Solar to Off: 3 tries, then the gave-up row "
|
||||
f"({zlog(r3o, 299)})", [x[1] for x in zlog(r3o, 299)] == [0.0] * 3
|
||||
and "charger_refused" in st3.get("rows", []))
|
||||
# The shutdown cancels a start write while it waits for its read-back (lag
|
||||
# 3 s): the 0 A must still go out (the earlier confirmed 0 A says nothing).
|
||||
rec3 = {}
|
||||
|
||||
|
||||
def _gate3(p, c):
|
||||
gate = asyncio.Event()
|
||||
|
||||
async def sleep(_s):
|
||||
gate.clear()
|
||||
await gate.wait()
|
||||
|
||||
async def settle():
|
||||
gate.set()
|
||||
for _ in range(5):
|
||||
await asyncio.sleep(0)
|
||||
c.charger._sleep = sleep
|
||||
c.car_settle = settle
|
||||
|
||||
|
||||
def _shut3(p, c, t):
|
||||
w = [x for x in p.wlog if x[1] == "current" and x[2] > 0]
|
||||
if w and "t" not in rec3:
|
||||
rec3["t"] = t
|
||||
rec3["co"] = shutdown_at(rec3)(p, c)
|
||||
|
||||
|
||||
def _kick3(p, c):
|
||||
return rec3.pop("co", None)
|
||||
|
||||
|
||||
_s3 = SimCharger(setpoint_a=10)
|
||||
_s3.lag_s = 3.0
|
||||
r3s = S.drive(dur=140, sim=_s3, on_cycle=_shut3,
|
||||
events={t: (_gate3 if t == 50 else _kick3)
|
||||
for t in range(50, 140)},
|
||||
**RUN10)
|
||||
s3s = rec3.get("sets", [])
|
||||
check(f"R3: shutdown while a start write waits for its read-back: the 0 A "
|
||||
f"still goes out before the inverters' 0 W ({s3s[:3]}, setpoint at the "
|
||||
f"end {r3s['sim'].setpoint_a})",
|
||||
any(x[1] == S.SET and x[2] == 0.0 for x in s3s)
|
||||
and s3s and s3s[0][1] == S.SET and r3s["sim"].setpoint_a == 0.0)
|
||||
# Major: one excess, one cut, from a car well above 6 A that is slow to show
|
||||
# it: a 700 W/s ramp (about 4 s), and also a 3 s read-back lag (about 7 s).
|
||||
# Batteries at the cut-out, so the cut is at once. Later writes in the period
|
||||
# are the spare rule (the step also takes the sun), not cuts.
|
||||
for lag in (0.0, 3.0):
|
||||
_s3c = SimCharger(setpoint_a=0)
|
||||
_s3c.ramp_w_s = 700.0
|
||||
r3c = S.drive(sim=_s3c, house=steps((0, 500.0), (910, 7900.0),
|
||||
(970, 500.0)),
|
||||
sun=const(13000.0), first="car", socs=CUTOUT, dur=1000,
|
||||
opts={"slew_w": 0},
|
||||
events={900: lambda p, c, lag=lag: setattr(p.ch, "lag_s",
|
||||
lag)})
|
||||
x3c = first_cut(r3c, 905)
|
||||
w3c = [(t, v) for t, v in S.writes(r3c) if 905 <= t < 940]
|
||||
want3c = (None if x3c is None else
|
||||
math.floor((16 * 690.0 - x3c["cut"]) / 690.0 + 1e-9))
|
||||
check(f"R3 cut, car 16 A on 3 phases, ramp 700 W/s, read-back lag "
|
||||
f"{lag:.0f} s:"
|
||||
f" one excess ({None if x3c is None else round(x3c['cut'])} W) "
|
||||
f"takes one cut, to {want3c} A, and no more ({w3c})",
|
||||
x3c is not None and len(w3c) == 1 and w3c[0][1] == want3c
|
||||
and want3c >= 11)
|
||||
print("\n(T39, T44, T45, T50 and T51, the long runs, are in test_ev05_long.py)")
|
||||
|
||||
print()
|
||||
|
||||
@@ -271,14 +271,18 @@ def fuzz(seed):
|
||||
st = {"sun": rnd.uniform(0, 9000), "house": rnd.uniform(200, 3000),
|
||||
"n": {}, "acts": [], "undo": [], "exits": []}
|
||||
|
||||
def exit_check(p, c):
|
||||
"""N9: Solar to Off with the charger above 0 A, reachable, taking
|
||||
writes and not held by another writer: a 0 A must follow."""
|
||||
def exit_check(p, c, kind="off"):
|
||||
"""N9: a way out of Solar (Off, Stop, shadow) with the charger above
|
||||
0 A, reachable and not held by another writer. Round 3: also while
|
||||
the charger refuses writes (judged after the refusal ends)."""
|
||||
ch = p.ch
|
||||
if c.car_mode == "solar" and not c.car_solar.hold \
|
||||
and not ch.unavailable and ch.refuse is None \
|
||||
and ch.readback_a > 0.5 and not p.ha_down:
|
||||
st["exits"].append(p.t)
|
||||
if c.car_mode == "solar" and c.car_writing() and not c.car_solar.hold \
|
||||
and not ch.unavailable and ch.readback_a > 0.5 \
|
||||
and not p.ha_down:
|
||||
st["exits"].append((p.t, kind, ch.refuse))
|
||||
|
||||
def at(t, fn):
|
||||
st["undo"].append((t, fn))
|
||||
|
||||
def later(p, fn):
|
||||
st["undo"].append((p.t + rnd.randint(10, 40), fn))
|
||||
@@ -325,10 +329,12 @@ def fuzz(seed):
|
||||
later(p, lambda: setattr(p, "meter_on", True))
|
||||
st["n"]["meter"] = st["n"].get("meter", 0) + 1
|
||||
elif r < 0.093:
|
||||
exit_check(p, c, "out")
|
||||
c.o["shadow_mode"] = "on"
|
||||
later(p, lambda: c.o.__setitem__("shadow_mode", "off"))
|
||||
st["n"]["shadow"] = st["n"].get("shadow", 0) + 1
|
||||
elif r < 0.095:
|
||||
exit_check(p, c, "out")
|
||||
c.auto = False
|
||||
later(p, lambda: setattr(c, "auto", True))
|
||||
st["n"]["stop"] = st["n"].get("stop", 0) + 1
|
||||
@@ -341,6 +347,28 @@ def fuzz(seed):
|
||||
return c.handle_action("car_mode", value=m)
|
||||
elif r < 0.1:
|
||||
ch.station_a = rnd.choice(stations)
|
||||
elif r < 0.1015 and c.car_mode == "solar" and c.car_writing() \
|
||||
and p.ch.readback_a > 0.5 and st.get("back") is None \
|
||||
and not p.ch.unavailable and p.ch.refuse is None:
|
||||
# Round 3: the charger refuses for 5 s, and a way out comes now
|
||||
# and stands 100-150 s.
|
||||
kind = rnd.choice(["off", "stop", "shadow"])
|
||||
p.ch.refuse = rnd.choice(["error", "ignore"])
|
||||
at(p.t + 5, lambda: setattr(p.ch, "refuse", None))
|
||||
exit_check(p, c, "off" if kind == "off" else "out")
|
||||
stay = rnd.randint(100, 150)
|
||||
st["n"]["refused_exit_made"] = \
|
||||
st["n"].get("refused_exit_made", 0) + 1
|
||||
if kind == "stop":
|
||||
c.auto = False
|
||||
at(p.t + stay, lambda: setattr(c, "auto", True))
|
||||
elif kind == "shadow":
|
||||
c.o["shadow_mode"] = "on"
|
||||
at(p.t + stay, lambda: c.o.__setitem__("shadow_mode", "off"))
|
||||
else:
|
||||
st["acts"].append(p.t)
|
||||
st["back"] = p.t + stay
|
||||
return c.handle_action("car_mode", value="off")
|
||||
elif r < 0.103 and c.car_mode == "solar" and p.ch.readback_a > 0.5 \
|
||||
and st.get("back") is None:
|
||||
exit_check(p, c) # leave Solar while it charges
|
||||
@@ -355,6 +383,7 @@ def fuzz(seed):
|
||||
|
||||
def note(p, c, t):
|
||||
ctx.append((t, c.car_mode, c.car_writing(), c.car_solar.single,
|
||||
p.ch.refuse, p.ch.unavailable, p.ch.setpoint_a,
|
||||
c.car_solar.hold, p.ch.station_a))
|
||||
r = S.drive(house=lambda t: st["house"], sun=lambda t: st["sun"],
|
||||
first="car", opts={"ev_margin_w": 0, "ev_start_min": 1,
|
||||
@@ -370,7 +399,7 @@ def fuzz(seed):
|
||||
# A write logged at second t comes after that second's actions.
|
||||
x = by_t.get(t) or by_t.get(t - 1)
|
||||
mode = x[1] if x else "?"
|
||||
if what == "current" and v > min(16.0, x[5] if x else 16.0) + 1e-9:
|
||||
if what == "current" and v > min(16.0, x[8] if x else 16.0) + 1e-9:
|
||||
bad.append(("N1 over the clamp", t, v))
|
||||
if what == "phases":
|
||||
if sp != 0.0:
|
||||
@@ -388,10 +417,27 @@ def fuzz(seed):
|
||||
if last_nz is not None and t - last_nz < 30 and not near_act:
|
||||
bad.append(("N5 two non-zero writes under 30 s", t, v))
|
||||
last_nz = t
|
||||
for te in st["exits"]:
|
||||
if not any(x[1] == "current" and x[2] == 0.0 and te <= x[0] <= te + 3
|
||||
for x in log):
|
||||
bad.append(("N9 Solar to Off left the current up", te))
|
||||
for te, kind, ref in st["exits"]:
|
||||
if ref is None:
|
||||
if not any(x[1] == "current" and x[2] == 0.0
|
||||
and te <= x[0] <= te + 3 for x in log):
|
||||
bad.append(("N9 a way out left the current up", te, kind))
|
||||
continue
|
||||
# Round 3: the charger refused when the way out came. Judged when the
|
||||
# refusal ended within 60 s and the way out still stands 80 s on (the
|
||||
# 0 A is tried again 60 s after the first try, +10 s read-back).
|
||||
span = [x for x in ctx if te <= x[0] <= te + 80]
|
||||
ends = next((x[0] for x in span if x[4] is None), None)
|
||||
still = len(span) >= 80 and all(
|
||||
(x[1] == "off" if kind == "off" else
|
||||
(x[1] == "solar" and not x[2])) and not x[5] and not x[7]
|
||||
for x in span)
|
||||
if ends is None or ends > te + 60 or not still:
|
||||
continue
|
||||
st["n"]["refused_exits"] = st["n"].get("refused_exits", 0) + 1
|
||||
if not any(x[6] <= 0.5 for x in span): # reached 0 A in it
|
||||
bad.append(("N9 a refused way-out 0 A was not tried again", te,
|
||||
kind))
|
||||
if r["c"].charger.clamp_faults:
|
||||
bad.append(("N1 clamp fault", r["c"].charger.clamp_faults))
|
||||
st["n"]["exits"] = len(st["exits"])
|
||||
@@ -412,10 +458,12 @@ check(f"T45: {fz_n} charger writes over 14 random Solar sites and 16800 steps "
|
||||
f"non-zero write in Off, in shadow "
|
||||
f"or stopped, none under 30 s apart ({fz_bad[:3]})",
|
||||
not fz_bad and fz_n > 100)
|
||||
check(f"T45: each disturbance happened ({fz_counts})",
|
||||
check(f"T45: each disturbance happened, and exits while the charger refused "
|
||||
f"were judged ({fz_counts})",
|
||||
all(fz_counts.get(k, 0) > 2 for k in ("plug", "down", "other", "meter",
|
||||
"shadow", "stop", "mode",
|
||||
"exits")))
|
||||
"exits"))
|
||||
and fz_counts.get("refused_exits", 0) >= 1)
|
||||
|
||||
print()
|
||||
if fails:
|
||||
|
||||
Reference in New Issue
Block a user