feat(frontend): always-visible gun bays, idle/plugged/charging lamp language, self-service password

- Control renders every gun declared in the chargers registry, even when
  the charger is offline or has not reported that connector yet (state
  shows Offline / No status yet in gray)
- owner-specified state language: gray = idle, pulsing blue = cable in
  the socket (Preparing), green = charging; suspended/finishing = steady
  blue; fault = red
- POST /api/me/password (requires current password) + /account page,
  username in the topbar links to it
- smoke test: 58 checks (password change round-trip incl. old-password
  invalidation)
This commit is contained in:
2026-07-12 08:37:20 +02:00
parent 75869364b0
commit 3387f8689e
11 changed files with 229 additions and 48 deletions
+77 -26
View File
@@ -14,31 +14,80 @@ interface Gun {
connector: number;
label: string;
chargerLabel: string;
ocppStatus: string;
ocppStatus: string; // OCPP status, or "Offline" / "NoStatus" synthesized here
tx: (ActiveTx & { txId: string }) | null;
}
/** Every gun the system knows about is ALWAYS shown: the chargers registry
* defines the cards, live connector reports and transactions overlay state. */
function gunsFrom(status: Status): Gun[] {
const txByGun = new Map<string, ActiveTx & { txId: string }>();
for (const [txId, tx] of Object.entries(status.active_transactions))
txByGun.set(`${tx.cp}/${tx.connector}`, { ...tx, txId });
const guns = new Map<string, Gun>();
return Object.entries(status.connectors)
.map(([key, ocppStatus]) => {
const [cp, conn] = [key.slice(0, key.lastIndexOf("/")), key.slice(key.lastIndexOf("/") + 1)];
return { cp, connector: Number(conn), ocppStatus };
})
.filter((g) => g.connector > 0)
.sort((a, b) => a.cp.localeCompare(b.cp) || a.connector - b.connector)
.map((g) => {
const meta = status.chargers[g.cp] ?? {};
return {
...g,
label: meta.guns?.[String(g.connector)] ?? `Gun ${g.connector}`,
chargerLabel: meta.label ?? g.cp,
tx: txByGun.get(`${g.cp}/${g.connector}`) ?? null,
};
});
for (const [cp, meta] of Object.entries(status.chargers)) {
const online = cp in status.connected;
for (const [conn, label] of Object.entries(meta.guns ?? {})) {
guns.set(`${cp}/${conn}`, {
cp,
connector: Number(conn),
label,
chargerLabel: meta.label ?? cp,
ocppStatus: online ? "NoStatus" : "Offline",
tx: null,
});
}
}
for (const [key, ocppStatus] of Object.entries(status.connectors)) {
const cp = key.slice(0, key.lastIndexOf("/"));
const connector = Number(key.slice(key.lastIndexOf("/") + 1));
if (connector <= 0) continue; // connector 0 = the whole charge point
const existing = guns.get(`${cp}/${connector}`);
if (existing) existing.ocppStatus = ocppStatus;
else
guns.set(`${cp}/${connector}`, {
cp,
connector,
label: `Gun ${connector}`,
chargerLabel: status.chargers[cp]?.label ?? cp,
ocppStatus,
tx: null,
});
}
for (const [txId, tx] of Object.entries(status.active_transactions)) {
const gun = guns.get(`${tx.cp}/${tx.connector}`);
if (gun) gun.tx = { ...tx, txId };
}
return [...guns.values()].sort(
(a, b) => a.cp.localeCompare(b.cp) || a.connector - b.connector,
);
}
/** Chip text + tone per the owner's state language. */
function gunState(gun: Gun): { label: string; cls: string } {
if (gun.tx) return { label: "Charging", cls: "charging" };
switch (gun.ocppStatus) {
case "Charging":
return { label: "Charging", cls: "charging" };
case "Preparing":
return { label: "Plugged in", cls: "plugged" };
case "SuspendedEV":
case "SuspendedEVSE":
return { label: "Paused", cls: "plugged" };
case "Finishing":
return { label: "Finishing", cls: "plugged" };
case "Available":
return { label: "Idle", cls: "idle" };
case "Offline":
return { label: "Offline", cls: "offline" };
case "NoStatus":
return { label: "No status yet", cls: "offline" };
case "Faulted":
return { label: "Fault", cls: "faulted" };
default:
return { label: gun.ocppStatus, cls: "idle" };
}
}
function GunBay({ gun, scopes }: { gun: Gun; scopes: string[] }) {
@@ -60,19 +109,18 @@ function GunBay({ gun, scopes }: { gun: Gun; scopes: string[] }) {
(r) => toast(`Stop command: ${r.remote_stop}`),
);
const state = gunState(gun);
return (
<article className="bay">
<header className="bay__head">
<span className="bay__eyebrow">{gun.chargerLabel}</span>
<Lamp tone={statusTone(gun.ocppStatus, !!gun.tx)} title={gun.ocppStatus} />
<Lamp tone={statusTone(gun.ocppStatus, !!gun.tx)} title={state.label} />
</header>
<h2 className="bay__title">{gun.label}</h2>
<div className="bay__status">
<span className={`chip chip--${gun.tx ? "live" : gun.ocppStatus.toLowerCase()}`}>
{gun.tx ? "Charging" : gun.ocppStatus}
</span>
<span className={`chip chip--${state.cls}`}>{state.label}</span>
{gun.ocppStatus === "Preparing" && !gun.tx && (
<span className="bay__hint">cable plugged — ready to start</span>
<span className="bay__hint">cable in the socket — ready to start</span>
)}
</div>
@@ -184,10 +232,13 @@ export default function Dashboard() {
<Lamp tone="red" />
<div>
<h2>Charger offline</h2>
<p>Waiting for the charge point to dial in. Guns appear here as soon as it connects.</p>
<p>Waiting for the charge point to dial in — controls enable as soon as it connects.</p>
</div>
</div>
)}
{!guns.length && !offline && (
<p className="empty">Connected, waiting for the first gun status report…</p>
)}
<div className="bays">
{guns.map((g) => (
<GunBay key={`${g.cp}/${g.connector}`} gun={g} scopes={me.scopes} />