From 25fa1f9fc5f71eef953d75870b888a1a8879e735 Mon Sep 17 00:00:00 2001 From: Julian Cuni Date: Sun, 12 Jul 2026 09:39:05 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20live=20telemetry=20on=20gun=20cards=20?= =?UTF-8?q?=E2=80=94=20SoC=20battery=20gauge,=20kW,=20V,=20A,=20delivered?= =?UTF-8?q?=20kWh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - backend keeps the latest meter sample per active transaction in memory and ships it as active_transactions[tx].telemetry on /api/status (Transaction.Begin snapshots skipped: taken before the BMS is read) - Battery component: fill + color sweep red (empty) -> blue (half) -> green (full) per the owner's spec; aria meter semantics - charging bays show the gauge, a prominent kW readout, and delivered kWh / voltage / current rows; hint while awaiting the first sample - smoke: 60 checks (telemetry rides /api/status) --- backend/csms.py | 7 +++ frontend/src/components/Battery.tsx | 41 ++++++++++++++++++ frontend/src/pages/Dashboard.tsx | 67 +++++++++++++++++++++++------ frontend/src/styles.css | 33 +++++++++++++- frontend/src/types.ts | 10 +++++ frontend/tsconfig.tsbuildinfo | 2 +- wiki/log.md | 4 ++ 7 files changed, 149 insertions(+), 15 deletions(-) create mode 100644 frontend/src/components/Battery.tsx diff --git a/backend/csms.py b/backend/csms.py index 26a264b..aec4008 100644 --- a/backend/csms.py +++ b/backend/csms.py @@ -215,6 +215,13 @@ class ChargePoint(OcppChargePoint): if reading: store.add_sample(tx, entry.get("timestamp", now()), context=context, **reading) + # live telemetry for the panel: latest sample rides + # /api/status. Transaction.Begin is skipped — it's taken + # before the car's BMS is read (SoC 0, all zeros). + if context != "Transaction.Begin" and tx in ACTIVE_TX: + ACTIVE_TX[tx].setdefault("telemetry", {}).update( + {**reading, "time": entry.get("timestamp")} + ) log.info("MeterValues: connector=%s values=%r", connector_id, meter_value) return call_result.MeterValues() diff --git a/frontend/src/components/Battery.tsx b/frontend/src/components/Battery.tsx new file mode 100644 index 0000000..888e838 --- /dev/null +++ b/frontend/src/components/Battery.tsx @@ -0,0 +1,41 @@ +/** State-of-charge gauge: a battery whose fill sweeps the owner-specified + * gradient — red (empty) → blue (half) → green (full). */ + +type RGB = [number, number, number]; +const RED: RGB = [191, 53, 39]; +const BLUE: RGB = [33, 96, 196]; +const GREEN: RGB = [23, 138, 92]; + +function mix(a: RGB, b: RGB, t: number): string { + const c = a.map((v, i) => Math.round(v + (b[i] - v) * t)); + return `rgb(${c[0]}, ${c[1]}, ${c[2]})`; +} + +export function socColor(soc: number): string { + const s = Math.max(0, Math.min(100, soc)); + return s <= 50 ? mix(RED, BLUE, s / 50) : mix(BLUE, GREEN, (s - 50) / 50); +} + +export default function Battery({ soc }: { soc: number | null | undefined }) { + const known = soc != null; + const pct = known ? Math.max(0, Math.min(100, soc)) : 0; + const color = known ? socColor(pct) : "transparent"; + return ( +
+ + + + + + {known ? `${Math.round(pct)}%` : "—"} + +
+ ); +} diff --git a/frontend/src/pages/Dashboard.tsx b/frontend/src/pages/Dashboard.tsx index 214135b..b66b0ef 100644 --- a/frontend/src/pages/Dashboard.tsx +++ b/frontend/src/pages/Dashboard.tsx @@ -1,4 +1,5 @@ import { api, scopeAllowed } from "../api"; +import Battery from "../components/Battery"; import { Lamp, statusTone } from "../components/Lamp"; import { useAction, useLiveRelays, useStatus } from "../queries"; import { useApp } from "../store"; @@ -127,20 +128,60 @@ function GunBay({ gun, scopes }: { gun: Gun; scopes: string[] }) { {gun.tx && ( -
-
-
By
-
{gun.tx.who || gun.tx.id_tag}
+ <> +
+ +
+ + {gun.tx.telemetry?.power_w != null + ? (gun.tx.telemetry.power_w / 1000).toFixed(1) + : "—"} + + kW +
-
-
Via
-
{gun.tx.method === "app" ? "In-app" : gun.tx.method === "card" ? "Card" : gun.tx.method}
-
-
-
Running
-
{fmtSince(gun.tx.started)}
-
-
+
+
+
By
+
{gun.tx.who || gun.tx.id_tag}
+
+
+
Via
+
{gun.tx.method === "app" ? "In-app" : gun.tx.method === "card" ? "Card" : gun.tx.method}
+
+
+
Running
+
{fmtSince(gun.tx.started)}
+
+
+
Delivered
+
+ {gun.tx.telemetry?.energy_wh != null + ? `${((gun.tx.telemetry.energy_wh - gun.tx.meter_start) / 1000).toFixed(2)} kWh` + : "—"} +
+
+
+
Voltage
+
+ {gun.tx.telemetry?.voltage_v != null + ? `${gun.tx.telemetry.voltage_v.toFixed(0)} V` + : "—"} +
+
+
+
Current
+
+ {gun.tx.telemetry?.current_a != null + ? `${gun.tx.telemetry.current_a.toFixed(1)} A` + : "—"} +
+
+
+ {!gun.tx.telemetry && ( + first meter reading arrives within a minute… + )} + )}