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… + )} + )}