"""EV-20: the peak guard and a Solar car (EV-21: as Off where Solar cannot cut it, as Manual's grading otherwise); Solar kWh; what stays unchanged; the strings, docs and settings; the write seam (T21, T22, T47-T52, T55, T57-T60). `python3 -B test_ev20_guard.py` The real Controller on `tools/ev20_sun.py` (N batteries, the sun, the house and `chargersim.SimCharger` on one meter, a 1 s cycle on a model clock), plus unit rows for the pure parts; shared pieces in `tools/ev20_kit.py`. Each section names the T-ids and N-ids of reports/EV-20-test-plan.md it implements. "Std run": Car first, both batteries full, house 500 W, sun 2900 W: spare 2400 W, the car target 2300 W = 10 A on 1 phase, written 120 s after the start. Times are the cycle's second; `race` runs use the production order (read, the writer settles, the cycle). Mutating a module this file grades? Read MUTATION.md first (purge __pycache__). """ import asyncio import json import math import os import random import sys HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, os.path.join(HERE, "tools")) from app import carmode, chargers as CH, ctl_car, homeview, messages # noqa: E402 from app import mqtt, validate, web, main as app_main # noqa: E402 from app.carmode import SolarPlan, amps_for, spare_w # noqa: E402 import ev20_sun as S # noqa: E402 from chargersim import SimCharger # noqa: E402 from ev20_kit import * # noqa: E402,F401,F403 from ev20_kit import LOG, check, fails, report # noqa: E402,F401 from named_absence import nth, present # noqa: E402,F401 from ev20_kit import (_dies, _err, _freeze_after_write, _shutdown, # noqa: E402,F401 _until) # =========================================================================== # print("\n8. THE PEAK GUARD: A SOLAR CAR SOLAR CANNOT CUT IS OFF'S (T21, T22, " "T47, T48; EV-21)") # =========================================================================== # ALARMS = S.ALARMS def twin(mode, **kw): return S.drive(kw.pop("house"), kw.pop("sun"), mode=mode, rows=True, **kw) def off_twin(rs, **kw): """EV-21: the Off twin of a Solar run: the same plant and events, and Solar's own writes put on the charger at the same seconds. Where Solar cannot cut the car (another writer, Stop, shadow, a safety stop), the alarm path, the banking and the guard are this twin's (Q5, OQ8, C2).""" ev = dict(kw.pop("events", None) or {}) rep_ = {} for t_sim, what, v, _pw, _sp in rs["sim"].log: rep_.setdefault(int(round(t_sim)), []).append((what, v)) for t, acts in rep_.items(): def put(p, c, acts=acts): for what, v in acts: (p.ch.set_current if what == "current" else p.ch.set_phases)(v) ev[t] = both(ev[t], put) if t in ev else put return twin("off", events=ev, **kw) def alarm_view(r, t0=0): """EV-21: the alarm path only (car_explains, red rows, the car figure); the car-over row is display and shows when Solar cannot cut (OQ5).""" return [(x["t"], x["explains"], tuple(x["red"]), x["alarm_w"] is None) for x in r["trace"] if x["t"] >= t0] def alarms_of(r): return [(t, n) for t, n in r["raised"] if n in ALARMS] def same_alarms(a, b): return len(a) == len(b) and all(abs(x[0] - y[0]) <= 2 and x[1] == y[1] for x, y in zip(a, b)) def notes(r): return [(t, n) for t, n in r["raised"] if n in ALARMS + (messages.ID_CAR_OVER,)] # (b) EV-05 r5 shape. for cover in (True, False): kw = dict(house=step_fn((1000, 3000.0), base=500.0), sun=const(7000.0), dur=1800, first="car", phases=3, socs={"a": 10.0, "b": 10.0}, opts={"ev_phases": "3", "ev_batt_cover": cover}, events={600: lambda p, c: p.ch.set_current(16)}) rs = twin("solar", **dict(kw)) rm = off_twin(rs, **dict(kw)) gs, gm = alarm_view(rs, 640), alarm_view(rm, 640) diff = [(a, b) for a, b in zip(gs, gm) if a[1:] != b[1:]] check(f"T21 (b{'' if cover else ', c'}) cover {'on' if cover else 'off'}:" f" another writer's 16 A in Solar (Solar cannot cut it) is graded " f"as the Off twin, every cycle from 640 s (EV-21; {len(diff)} " f"differ: {diff[:2]})", not diff) ns, nm = alarms_of(rs), alarms_of(rm) over_s = [t for t, n in rs["raised"] if n == messages.ID_CAR_OVER] check(f"T21 (b) cover {'on' if cover else 'off'}: the Off twin's alarms " f"at the same seconds +2 s, never silent ({ns} vs {nm}); the " f"car-over note shows, as Solar cannot cut ({over_s[:1]})", same_alarms(ns, nm) and bool(ns) and bool(over_s)) check(f"T21: the car's banked quarters are the Off twin's " f"({rs['c'].car_peak_q} vs {rm['c'].car_peak_q})", rs["c"].car_peak_q == rm["c"].car_peak_q) if not cover: pj = [(round(a["proj"] or 0), round(b["proj"] or 0)) for a, b in zip(rs["trace"], rm["trace"]) if a["t"] >= 640 and round(a["proj"] or 0) != round(b["proj"] or 0)] check(f"T21 (c): with the cover off and Solar unable to cut, the " f"guard keeps the car in, as the Off twin (Q-A; {pj[:2]})", not pj) # T21 (a): car_cycle itself, fed the same projection, guard and reading on # two Controllers that differ only in the mode (the twins of (c), now). cs, cm = rs["c"], rm["c"] proj_s, guard_s = cs._peak_proj_real, cs.peak_guard same_in = (proj_s == cm._peak_proj_real and cs.car.reading == cm.car.reading) cs.car_cycle(proj_s, guard_s, 3400.0, None) cm.car_cycle(proj_s, guard_s, 3400.0, None) check(f"T21 (a): car_cycle on the same projection and reading gives the " f"same car_alarm_w (None) and car_explains in Solar, under another " f"writer, as in Off (EV-21, C2; inputs equal {same_in}; " f"{cs.car_alarm_w()} {cs.car_explains} vs {cm.car_alarm_w()} " f"{cm.car_explains})", same_in and (cs.car_alarm_w(), cs.car_explains) == (cm.car_alarm_w(), cm.car_explains) and cs.car_alarm_w() is None) over_note = [x for x in rs["plant"].notes if x[1] == messages.ID_CAR_OVER] check("T21 D1: Solar's car-over notice reads 'Solar charges the car at 16 A' " "(the charger's current), never Manual's stored value", messages.car_over_solar("16").body.startswith( "Solar charges the car at 16 A") and "You set" not in messages.car_over_solar("16").body) # (d) EV-05 r6 shape: Stop / shadow / circ_wd at 500 s, other writer at 600. for name, fn, opts in (("Stop (auto)", lambda p, c: setattr(c, "auto", False), {"shadow_mode": "auto"}), ("shadow on", lambda p, c: c.o.__setitem__( "shadow_mode", "on"), {}), ("circ_wd", lambda p, c: setattr(c.circ_wd, "tripped", True), {})): kw = dict(house=step_fn((1000, 3000.0), base=500.0), sun=const(7000.0), dur=1500, first="car", phases=3, socs={"a": 10.0, "b": 10.0}, opts=dict({"ev_phases": "3"}, **opts), events={500: fn, 600: lambda p, c: p.ch.set_current(16)}) rs = twin("solar", **dict(kw)) rm = off_twin(rs, **dict(kw)) gs, gm = alarm_view(rs, 640), alarm_view(rm, 640) diff = [(a, b) for a, b in zip(gs, gm) if a[1:] != b[1:]] check(f"T21 (d) [{name}]: graded as the Off twin each cycle (EV-21; " f"{len(diff)} differ: {diff[:1]}); alarms " f"{alarms_of(rs)} vs {alarms_of(rm)}; banked as Off", not diff and same_alarms(alarms_of(rs), alarms_of(rm)) and rs["c"].car_peak_q == rm["c"].car_peak_q) # T22: EV-15 shapes in Solar: Solar's own 3 -> 1 sequence and own 0 A pause # with both batteries at the reserve. for name, sun_fn in ( ("own 3 -> 1 sequence", step_fn((300, 600.0 + 4600.0), (700, 600.0 + 3700.0), base=600.0 + 3000.0)), ("own 0 A pause", step_fn((700, 600.0 + 600.0), base=600.0 + 4600.0))): kw = dict(house=const(600.0), sun=sun_fn, dur=1800, first="car", socs={"a": 19.0, "b": 19.0}, opts={"peak_soc_floor": 20, "ev_pause_min": 5}) rs = twin("solar", **kw) reds = [(x["t"], x["red"]) for x in rs["trace"] if x["red"]] check(f"T22 [{name}]: no PEAK_GUARD_FLOOR_LIMITED / saturated, no " f"goodwe_peak_soc_floor, no red row in any second " f"({notes(rs)}, {reds[:2]}; writes {cur_writes(rs)[-3:]})", not [n for _, n in notes(rs) if n in ALARMS] and not reds and (name != "own 0 A pause" or [a for _, a, _ in cur_writes(rs)][-1:] == [0.0])) def _overload(p, c): p.house = const(25000.0) kw = dict(house=const(600.0), sun=step_fn((300, 600.0 + 4600.0), (700, 600.0 + 3700.0), base=600.0 + 3000.0), dur=1200, first="car", socs={"a": 19.0, "b": 19.0}, opts={"peak_soc_floor": 20}) rs = twin("solar", **dict(kw, events={1006: _overload})) seq_at = [x[0] for x in selects(rs)] ro = twin("off", **dict(kw, events={1006: _overload}), plug=False) a_s = [t for t, n in notes(rs) if n in ALARMS] a_o = [t for t, n in notes(ro) if n in ALARMS] check(f"T22: a 25 kW house overload 6 s into Solar's sequence (select at " f"{seq_at}): the alarm at the same second as with the car Off (+2 s) " f"({a_s[:1]} vs {a_o[:1]})", a_s and a_o and abs(a_s[0] - a_o[0]) <= 2) # T47: EV-05 r7 M2 / r8 M2 / r9 Minor: another writer starts the car after # Solar's own 0 A pause. for T in (615, 640, 680): kw = dict(house=step_fn((T + 5, 3000.0), base=500.0), sun=step_fn((300, 0.0), base=7000.0), dur=T + 200, first="car", phases=3, socs={"a": 10.0, "b": 10.0}, opts={"ev_phases": "3"}, events={T: lambda p, c: p.ch.set_current(16)}) rs = twin("solar", **dict(kw)) rm = off_twin(rs, **dict(kw)) gs, gm = alarm_view(rs, T), alarm_view(rm, T) diff = [(a, b) for a, b in zip(gs, gm) if a[1:] != b[1:]] own = [x["t"] for x in rs["trace"] if x["t"] >= T and x["own"]] z = [t for t, a, _ in cur_writes(rs) if a == 0.0] check(f"T47 [T={T}]: Solar's own 0 A at {z[:1]}; the other writer's car " f"never counts as Solar's own pause (own-pause seconds from T: " f"{own[:3]}), rows and car_explains as the Off twin (EV-21; " f"{len(diff)} differ: {diff[:1]})", bool(z) and not own and not diff) # Solar's own pause is graded as its own for at most OWN_PAUSE_MAX_S. kw = dict(house=const(500.0), sun=step_fn((300, 0.0), base=7000.0), dur=1200, first="car", phases=3, socs={"a": 10.0, "b": 10.0}, opts={"ev_phases": "3"}) rs = twin("solar", **kw) z = [t for t, a, _ in cur_writes(rs) if a == 0.0] own = [x["t"] for x in rs["trace"] if x["own"]] check(f"T47: the grace of Solar's own 0 A (at {z[:1]}) lasts at most " f"OWN_PAUSE_MAX_S ({ctl_car.OWN_PAUSE_MAX_S:.0f} s): own-pause seconds " f"{own[:1]}..{own[-1:]}", bool(z) and bool(own) and own[0] >= z[0] - 1 and own[-1] - z[0] <= ctl_car.OWN_PAUSE_MAX_S + 1) # T48: EV-05 r9 Major 2, a read-back later than TOOK_S. def _lag(on): def f(p, c): p.ch.lag_s = 12.0 if on else 0.0 return f for race in (False, True): tag = "race" if race else "step" n = LOG.mark() kw = dict(sun=step_fn((200, 3600.0), base=2900.0), race=race, rows=True) rl = std(1300, events={190: _lag(True), 260: _lag(False)}, **kw) r0 = std(1300, **kw) wl = cur_writes(rl) trl = rl["trace"] refused = [m for m in LOG.since(n, "WARNING") if "CHARGER_REFUSED" in m] check(f"T48 [{tag}]: the 13 A write at 200 s is not confirmed in 10 s and " f"shows at ~213 s: within 1 cycle it counts as taken (no retry at " f"260 s, no fail count, no CHARGER_REFUSED, no hold, no amber row) " f"({wl})", [a for _, a, _ in wl] == [10.0, 13.0] and wl[1][2] is False and trl[215]["taken"] and trl[215]["fails"] == 0 and not refused and not any(x["hold"] for x in trl) and not [a for x in trl if x["t"] >= 216 for a in x["amber"] if a.startswith(("charger", "car"))]) d48 = [(a["t"], a["explains"], a["over"], b["explains"], b["over"]) for a, b in zip(trl, r0["trace"]) if a["t"] >= 230 and (a["explains"], a["over"]) != (b["explains"], b["over"])] q1, q0 = rl["c"].car_peak_q, r0["c"].car_peak_q check(f"T48 [{tag}]: car_explains and car_over equal the no-lag twin; " f"car_peak_q banks the same quarters, within the 12 s of 10 A the " f"lag cost ({d48[:2]}; {q1} vs {q0})", not d48 and sorted(q1) == sorted(q0) and all(abs(q1[k] - q0[k]) <= 12.0 for k in q0)) # =========================================================================== # print("\n9. SOLAR kWh (T49), MANUAL, GUARD AND LOOP UNCHANGED (T57-T60)") # =========================================================================== # def kwh(r): c = r["c"] return c.car_sun_kwh(), c.car.today_kwh r49a = std(3700, sun=const(3500.0)) # spare 3000: 12 A, 2760 W r49b = S.drive(const(900.0), const(7900.0), dur=3700, first="batteries", socs={"a": 71.0, "b": 100.0}) r49c = std(3700, sun=step_fn((130, 1500.0), base=3500.0), opts={"ev_pause_min": 30}) r49d = std(3700, sun=step_fn((130, 0.0), base=3500.0), opts={"ev_pause_min": 30}) r49e = std(3700, mode="manual", sun=const(3500.0 + 2760.0)) k = {x: kwh(r) for x, r in (("a", r49a), ("b", r49b), ("c", r49c), ("d", r49d), ("e", r49e))} print(f" kWh (sun, today): {k}") check("T49 (a): Car first, spare 3000, the car 2760 W for ~1 h: the sun share " "is all of it (+-10 Wh of the car's own count)", k["a"][0] is not None and abs(k["a"][0] - k["a"][1]) <= 0.01 and abs(k["a"][0] - 2760.0 * (3700 - 121) / 3.6e6) <= 0.02) check("T49 (b): Batteries first, scenario 2 (spare 7000, room 5000, car " "1840 W): all of the car's 1.84 kWh from the sun", abs(k["b"][0] - k["b"][1]) <= 0.01 and 1.75 <= k["b"][0] <= 1.86) hold49 = [x["t"] for x in r49c["trace"] if x["why"] == "hold"] h49 = (hold49[-1] - hold49[0] + 1) if hold49 else 0 check(f"T49 (c): Car first hold, spare 1000 W, the car 1380 W: per hour 1.00 " f"of the 1.38 kWh; the hold lasts ev_pause_min, at most 30 min " f"({h49} s here), so 1000/1380 of the hold's energy (the hold's grid or " f"battery share is not counted)", abs(k["c"][0] - 1000.0 * h49 / 3.6e6) <= 0.02 and abs((k["c"][1] - k["c"][0]) - 380.0 * h49 / 3.6e6) <= 0.02) check("T49 (d): a negative spare: nothing from the sun (only the 10 A before " "the cloud)", k["d"][0] <= 0.01 + 2300.0 * 15 / 3.6e6) check("T49 (e): Manual at 10 A with 3 kW export: 0 kWh from the sun", k["e"][0] in (None, 0.0) and k["e"][1] > 1.0) check("T49: 0 <= sun <= today, always", all(v[0] is None or 0.0 <= v[0] <= (v[1] or 0.0) + 1e-9 for v in k.values())) c49 = r49a["c"] vals = c49.car_values() blk49 = homeview.car_block(c49, None) check(f"T49: the sensor goodwe_car_today_solar_kwh and the card agree " f"({vals.get('car_today_solar_kwh')}, {blk49['today']!r})", vals.get("car_today_solar_kwh") == round(k["a"][0], 3) and blk49["today"].endswith("from the sun.") and f"{k['a'][0]:.1f}" in blk49["today"]) c49.car.day = "2099-01-01" c49._car_sun_tick(c49.car_now()) check("T49 (f): at day rollover it is back to 0", c49.car_sun["kwh"] == 0.0 and c49.car_sun["day"] == "2099-01-01") # T57: Manual ignores Solar's settings; Manual's shutdown fail state. rm1 = std(600, mode="manual", opts={"ev_margin_w": 0, "ev_start_min": 1}) rm2 = std(600, mode="manual", first="batteries", events={100: act("car_sun_first", "car")}) check("T57: Manual ignores sun_first, the margin and the dwells: the same " "writes", [(x[0], x[2]) for x in rm1["sim"].log] == [(x[0], x[2]) for x in rm2["sim"].log]) rm3 = std(300, mode="manual", finale=_shutdown) check("T57: Manual's fail state at shutdown: the current stands (no write)", not [x for x in rm3["plant"].sets if x[1] == SET and x[0] >= 299]) # T58: Solar with no car vs no charger: the guard and the commands. spikes = step_fn((300, 2500.0), (900, 6500.0), (1500, 1200.0), (2400, 4800.0), base=900.0) g1 = S.drive(spikes, const(0.0), dur=3600, first="car", plug=False, socs={"a": 60.0, "b": 60.0}) g2 = S.drive(spikes, const(0.0), dur=3600, first="car", plug=False, socs={"a": 60.0, "b": 60.0}, opts={"ev_charger": "off"}) cm1 = [(t, e, v) for t, e, v in g1["plant"].sets if e.startswith("number.sp_")] cm2 = [(t, e, v) for t, e, v in g2["plant"].sets if e.startswith("number.sp_")] pg = [(a["t"], a["floor"], a["want"]) for a, b in zip(g1["trace"], g2["trace"]) if (a["floor"], a["want"], a["proj"]) != (b["floor"], b["want"], b["proj"])] check(f"T58: Solar with no car (state A) for an hour of house steps against " f"ev_charger off: the guard's floor, want and projection and every " f"inverter command are bit-identical ({len(cm1)} commands, {pg[:1]})", cm1 == cm2 and not pg and g1["sim"].log == []) # T59: the zero-grid loop with the car as a Solar car, or as a house load. l1 = std(1200, sun=step_fn((400, 4500.0), (800, 2500.0), base=3500.0), socs={"a": 60.0, "b": 60.0}) car1 = {x["t"]: x["car"] for x in l1["trace"]} def house2(ts): return 500.0 + car1.get(float(round(ts + S.SAMPLE_LEAD_S)), 0.0) l2 = S.drive(house2, step_fn((400, 4500.0), (800, 2500.0), base=3500.0), dur=1200, first="car", plug=False, socs={"a": 60.0, "b": 60.0}, opts={"ev_charger": "off"}) lc1 = [(t, e, v) for t, e, v in l1["plant"].sets if e.startswith("number.sp_")] lc2 = [(t, e, v) for t, e, v in l2["plant"].sets if e.startswith("number.sp_")] dif = [(a, b) for a, b in zip(lc1, lc2) if a != b] check(f"T59: the same meter series with the car as a Solar car and as a " f"house load: the loop's commands are identical ({len(lc1)} vs " f"{len(lc2)}, {dif[:1]}); the batteries charge what the car leaves", lc1 == lc2 and min(v for _, _, v in lc1) < -500.0) # T60: the House tile and the profile leave the car out in Solar. r60 = S.drive(const(900.0), const(7900.0), dur=200, first="car", socs={"a": 71.0, "b": 100.0}) c60 = r60["c"] check(f"T60: in Solar the House tile and HouseProfile take the car out " f"(car_term {c60.car_term()}, the car {r60['sim'].power_w:.0f} W)", c60.car_term()[1] is False and r60["sim"].power_w > 1000.0 and abs(c60.car_term()[0] - r60["sim"].power_w) < 1.0) # =========================================================================== # print("\n10. STRINGS, DOCS, SETTINGS (T50, T51, T52), THE SEAM (T55)") # =========================================================================== # from app import uitext # noqa: E402 import style_rules # noqa: E402 KEYS = ("why.solar_batt", "why.solar_car", "why.solar_paused", "help_solar.description", "first", "first_help.description") bad50 = [] for lang in ("en", "nl"): words_ = uitext.words(lang) for key in KEYS: node = words_["home_words"]["car"] if key.startswith("why") \ else words_["home"]["car"] for part in key.split("."): node = node.get(part, {}) if isinstance(node, dict) else {} text = uitext.say(node, kw="2.0 kW", s="5", a="8") \ if isinstance(node, str) else "" n_s = style_rules.sentences(text) long_ = [s for s in text.split(". ") if len(style_rules.words(s)) > 12] if not text or n_s > 2 or long_: bad50.append((lang, key, text)) check(f"T50: why.solar_batt, why.solar_car, why.solar_paused, help.solar, " f"first and first.help in EN and NL: <= 2 sentences of <= 12 words " f"({bad50})", not bad50) en_why = uitext.words("en")["home_words"]["car"]["why"]["solar_over"] check(f"T50 D1: the card's Why reads exactly 'Solar charges the car at {{a}} " f"A. This sets the peak.' ({en_why!r}); the notice and row carry the " f"same words in one sentence (STYLE.md's rule for a grey note and row)", en_why == "Solar charges the car at {a} A. This sets the peak." and messages.row_car_over_solar("8").startswith( "Solar charges the car at 8 A") and messages.car_over_solar("8").body_nl) check("T50 guard: Manual's car_over notice and row are unchanged", messages.car_over("16").body == "You set 16 A, which takes this " "15-minute period over the peak limit." and str(messages.row_car_over()) == "The car charge you set takes this " "15-minute period over the peak limit.") check("T50 D3: the shutdown warning in EN and NL", messages.car_release_failed().title == "Car may still be charging" and "0 A" in messages.car_release_failed().body and "0 A" in messages.car_release_failed().body_nl) docs = open(os.path.join(HERE, "DOCS.md"), encoding="utf-8").read() chlog = open(os.path.join(HERE, "CHANGELOG.md"), encoding="utf-8").read() nri = chlog.find("Not in a release yet") check("T51: DOCS 'Car charger' has a Solar section, a DECISIONS file for EV-20 " "exists, and a CHANGELOG line under 'Not in a release yet'", "**Solar mode.**" in docs and os.path.exists(os.path.join(HERE, "DECISIONS", "EV-20-solar-mode.md")) and nri >= 0 and "EV-20" in chlog[nri:nri + 4000]) check("T51: the shipped defaults ev_margin_w 100, ev_pause_min 5, " "ev_start_min 2, as config.yaml", CH.EV_OPTION_DEFAULTS["ev_margin_w"] == 100 and CH.EV_OPTION_DEFAULTS["ev_pause_min"] == 5 and CH.EV_OPTION_DEFAULTS["ev_start_min"] == 2) cfg = open(os.path.join(HERE, "config.yaml"), encoding="utf-8").read() schema = {k: v for k, v in (("ev_margin_w", "int(0,1000)"), ("ev_pause_min", "int(1,30)"), ("ev_start_min", "int(1,30)"))} check("T52: config.yaml's schema holds the same ranges as the validator", all(f" {k}: {v}" in cfg for k, v in schema.items()) and CH.SOLAR_RANGES == {"ev_margin_w": (0, 1000), "ev_pause_min": (1, 30), "ev_start_min": (1, 30)}) base_opts = {"ev_charger": "alfen_ha", "ev_current_entity": SET} bad52, ok52 = [], [] for key, vals, good in (("ev_margin_w", (-1, 1001), (0, 1000, 100)), ("ev_pause_min", (0, 31), (1, 30, 5)), ("ev_start_min", (0, 31), (1, 30, 2))): for v in vals: probs = validate._charger_problems(dict(base_opts, **{key: v}), {}) if not any(messages.LABELS[key] in p for p in probs): bad52.append((key, v, probs)) for v in good: probs = validate._charger_problems(dict(base_opts, **{key: v}), {}) if probs: ok52.append((key, v, probs)) check(f"T52: -1/1001, 0/31, 0/31 are refused with a message naming the " f"setting ({bad52[:1]})", not bad52) check(f"T52: the edges and the defaults are accepted ({ok52[:1]})", not ok52) def seam_callers(): import ast import io out = [] for f in sorted(os.listdir(os.path.join(HERE, "app"))): if not f.endswith(".py") or f == "chargers.py": continue tree = ast.parse(io.open(os.path.join(HERE, "app", f), encoding="utf-8").read()) for n in ast.walk(tree): if isinstance(n, ast.Call) and isinstance(n.func, ast.Attribute) \ and (n.func.attr in ("write_current", "write_phases") or (n.func.attr == "release" and "charger" in ast.dump(n.func.value))): out.append((f, n.func.attr)) return sorted(out) check(f"T55: the write seam is still exactly carmode.py's write_current and " f"write_phases ({seam_callers()}); Solar and release() go through them", seam_callers() == [("carmode.py", "write_current"), ("carmode.py", "write_phases")] and carmode.SolarWriter._write is not carmode.ManualWriter._write and "super()._write" in open(os.path.join(HERE, "app", "carmode.py"), encoding="utf-8").read()) report()