EV-03: car charger seam, Alfen HA driver, read-only Car card
Read-only: nothing in this change writes to the charger. - app/chargers.py: ChargerDriver, AlfenHaDriver, UnavailableCharger, ChargerReading, CarTracker - options ev_charger/ev_current_entity/ev_max_a/ev_phases (default off), Settings group, validator, census - Car card on Home, unreachable row and notification, two-writer info row, MQTT sensors - car out of the House tile and the house profile - tools/chargersim.py charger model, test_ev03.py Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -72,16 +72,26 @@ def flow(w, *, shadow=False):
|
||||
return "resting"
|
||||
|
||||
|
||||
def now_block(*, grid_w, pv_w, batt_w, has_solar, shadow, settled=True):
|
||||
def now_block(*, grid_w, pv_w, batt_w, has_solar, shadow, settled=True,
|
||||
car_w=0.0, car_unknown=False):
|
||||
"""The four tiles. `house_w` needs all three readings, so without a solar
|
||||
reading it is None rather than a number that leaves the sun out."""
|
||||
reading it is None rather than a number that leaves the sun out.
|
||||
|
||||
EV-03: `car_w` is what a car charger takes, and it is not the house, so it
|
||||
is taken out of House (the Car card shows it). `car_unknown` is a charger
|
||||
whose reading is not fresh: House then has no figure rather than one that
|
||||
may hold the car. Both default to "no charger", the figure as before."""
|
||||
house, disagree = None, False
|
||||
if has_solar and None not in (grid_w, pv_w, batt_w):
|
||||
house = float(grid_w) + float(pv_w) + float(batt_w)
|
||||
house = float(grid_w) + float(pv_w) + float(batt_w) - float(car_w or 0.0)
|
||||
if car_unknown:
|
||||
house = None
|
||||
# The three are read at slightly different moments, so the sum can dip
|
||||
# under zero. Inside the idle band that is 0 W; beyond it the readings
|
||||
# disagree and no house figure is shown.
|
||||
if house < -IDLE_W:
|
||||
if house is None:
|
||||
pass
|
||||
elif house < -IDLE_W:
|
||||
house, disagree = None, True
|
||||
elif house < 0.0:
|
||||
house = 0.0
|
||||
@@ -1070,6 +1080,7 @@ ATTN_DOCS = {
|
||||
"not_keeping_up": messages.T_LOOP_BOUND,
|
||||
"circulating": messages.T_CIRCULATING,
|
||||
"delivery": messages.S_NOT_DELIVERING,
|
||||
"charger": messages.T_CHARGER_UNREACH,
|
||||
}
|
||||
|
||||
|
||||
@@ -1187,7 +1198,10 @@ def _build(c, *, level, checks, now, held=None, waiting=False):
|
||||
"sub": banner_sub(kind)},
|
||||
"now": now_block(grid_w=c.grid, pv_w=c.pv_w, batt_w=c.site_batt_w,
|
||||
has_solar=bool(c.pv_roster), shadow=shadow,
|
||||
settled=settled),
|
||||
settled=settled,
|
||||
**dict(zip(("car_w", "car_unknown"),
|
||||
c.car_term()))),
|
||||
"car": car_block(c, now),
|
||||
"batteries": rows,
|
||||
"plan": plan,
|
||||
"modes_on": bool(getattr(c, "modes_on", False)),
|
||||
@@ -1208,6 +1222,85 @@ def _docs_url():
|
||||
messages._site["ha"])
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# EV-03: the Car card. READ ONLY: Off is the only mode in this version.
|
||||
# --------------------------------------------------------------------------- #
|
||||
_CAR_KIND = {"charging": "ok", "full": "ok", "unreach": "warn",
|
||||
"setup": "warn"}
|
||||
|
||||
|
||||
def car_state_word(key) -> str:
|
||||
return _t("car.state." + (key if key else "wait"))
|
||||
|
||||
|
||||
def car_phases_word(n) -> str:
|
||||
return _t("car.phase_one") if n == 1 else _t("car.phase_many", n=n)
|
||||
|
||||
|
||||
def _car_big(key, c, r, good):
|
||||
if key == "charging" and r is not None and r.power_w is not None:
|
||||
parts = [_dec(f"{r.power_w / 1000:.1f}")
|
||||
+ " kW"]
|
||||
amps = (r.allowed_a if r.allowed_a is not None
|
||||
else max(r.current_a) if r.current_a else None)
|
||||
if amps is not None:
|
||||
parts.append(f"{amps:.0f} A")
|
||||
n = c.car.phases_in_use()
|
||||
if n:
|
||||
parts.append(car_phases_word(n))
|
||||
return " · ".join(parts)
|
||||
if key == "unreach":
|
||||
t = c.car.last_good_utc
|
||||
return (_t("car.big.seen", t=hhmm(t)) if t is not None
|
||||
else _t("car.big.no_reading"))
|
||||
if key == "charging": # the reading is too old
|
||||
return _t("car.big.no_reading")
|
||||
return _t("car.big." + (key or "wait"))
|
||||
|
||||
|
||||
def _car_why(key, c, good):
|
||||
brand = (getattr(c.charger, "brand", "") or "Alfen")
|
||||
if key == "unreach":
|
||||
a = None if good is None else good.setpoint_a
|
||||
if a is None and good is not None:
|
||||
a = good.allowed_a
|
||||
if a is not None:
|
||||
return _t("car.why.unreach_a", a=f"{a:.0f}", brand=brand)
|
||||
return _t("car.why.unreach", brand=brand)
|
||||
if key == "setup":
|
||||
why = {"not_found": "not_found", "limit": "limit"}.get(
|
||||
c.charger_refused or "", "name")
|
||||
return _t("car.why." + why)
|
||||
return _t("car.why." + (key if key else "wait"))
|
||||
|
||||
|
||||
def car_block(c, now):
|
||||
"""The Car card for `/status`, or None when no charger is switched on (the
|
||||
page then draws nothing, as before)."""
|
||||
if not getattr(c, "car_enabled", False):
|
||||
return None
|
||||
mono = c.car_now()
|
||||
configured = c.charger.configured()
|
||||
key = c.car.status(mono, configured)
|
||||
r = c.car.reading if configured else None
|
||||
good = c.car.last_good
|
||||
fresh = configured and c.car.fresh(mono)
|
||||
today = None
|
||||
if configured and c.car.today_kwh is not None:
|
||||
today = _t("car.today", kwh=_kwh(c.car.today_kwh))
|
||||
return {
|
||||
"state": key or "wait",
|
||||
"chip": car_state_word(key),
|
||||
"kind": _CAR_KIND.get(key, "muted"),
|
||||
"big": _car_big(key, c, r if fresh else None, good),
|
||||
"today": today,
|
||||
"why": _car_why(key, c, good),
|
||||
"mode": "off",
|
||||
"power_w": (None if not fresh or r is None or r.power_w is None
|
||||
else round(float(r.power_w), 1)),
|
||||
}
|
||||
|
||||
|
||||
# =========================================================================== #
|
||||
# The words. STYLE.md: plain, short, present tense. A plan line is at most
|
||||
# two sentences of at most 12 words each (UX-13 design, section 4); a title at
|
||||
@@ -1715,6 +1808,13 @@ def _samples() -> list:
|
||||
out += [("plan", day_note(k, pct=70, name="Battery A", at="08:15",
|
||||
kwh="9.2 kWh", count="6.4 kWh"))
|
||||
for k in words["day"]]
|
||||
out += [("title", _t("car.state." + k)) for k in words["car"]["state"]]
|
||||
out += [("plan", _t("car.big." + k, t="09:12")) for k in
|
||||
words["car"]["big"]]
|
||||
out += [("plan", _t("car.why." + k, a="10", brand="Alfen"))
|
||||
for k in words["car"]["why"]]
|
||||
out += [("plan", _t("car.today", kwh="14.2 kWh")),
|
||||
("plan", "11.0 kW · 16 A · " + _t("car.phase_many", n=3))]
|
||||
out += [("plan", line_no_trade(k)) for k in
|
||||
("not_covered", "no_prices", "peak", "not_firm", "not_worth",
|
||||
"no_level")]
|
||||
|
||||
Reference in New Issue
Block a user