Collection
Mobility / EV Charging · v0.2.0Validated
Triage open charger faults by severity and inspect their codes and reset eligibility.
Charger Fault Review · Preview
Loading widget…
Preparing source code…
Idle
Mobility / EV Charging · v0.2.0Validated
Triage open charger faults by severity and inspect their codes and reset eligibility.
Loading widget…
Preparing source code…
Load the Lumo theme once in your app entry point. The example uses the local Lumo workspace packages.
import "@lumo/tokens/tokens.css";
import { FaultDeckWidget } from "@lumo/widgets/catalog/ev-charging/fault-deck";
export default function Example() {
return <FaultDeckWidget />;
}Props for integrating the React component in your app.
snapshotChargerFaultSnapshot | null (optional)onAction(action: ChargerFaultAction) => void | Promise<void>{
"snapshot": {
"network": "Harbour charge network",
"asOf": 1795602600000,
"faults": [
{
"id": "f16",
"charger": "North Market 02",
"connector": "CCS · A",
"summary": "Controller offline",
"code": "OtherError",
"severity": "high",
"reportedAt": 1795601880000,
"canReset": true
}
]
}
}"use client";
import { BatteryWarning } from "lucide-react";
import { useOperationSnapshot, validTimestamp } from "../../shared/operation-snapshot";
import { WidgetOperations, type OperationRow } from "../../shared/WidgetOperations";
import { chargerFaultDemo } from "./fault-deck.constants";
import type { ChargerFaultSnapshot, ChargerFaultAction } from "./fault-deck.types";
export type { ChargerFaultSnapshot, ChargerFaultAction, ChargerFault } from "./fault-deck.types";
const priorities = { critical: 0, high: 1, medium: 2 };
function age(at: number, asOf: number) {
if (!validTimestamp(at) || !validTimestamp(asOf) || at > asOf) return "Age unavailable";
const minutes = Math.floor((asOf - at) / 60_000);
return minutes >= 60 ? `${Math.floor(minutes / 60)} h ${minutes % 60} min` : `${minutes} min`;
}
export function FaultDeckWidget({ snapshot, onAction }: {
index?: number; snapshot?: ChargerFaultSnapshot | null;
onAction?: (action: ChargerFaultAction) => void | Promise<void>;
} = {}) {
const { data, action } = useOperationSnapshot(snapshot, chargerFaultDemo, onAction, (state, request) => ({
...state, faults: state.faults.map(fault => fault.id === request.faultId ? { ...fault, resetStatus: "pending" as const } : fault),
}));
const rows = data ? data.faults.slice().sort((a, b) => priorities[a.severity] - priorities[b.severity] || a.reportedAt - b.reportedAt)
.map<OperationRow<ChargerFaultAction>>(fault => ({
id: fault.id, label: fault.charger, caption: fault.summary, value: age(fault.reportedAt, data.asOf),
status: fault.severity === "critical" ? { label: "Critical", tone: "danger" }
: fault.severity === "high" ? { label: "High", tone: "warning" } : { label: "Medium", tone: "neutral" },
details: [["Connector", fault.connector], ["OCPP code", fault.code], ["Vendor code", fault.vendorCode ?? "Unavailable"], ["Reset", fault.resetStatus ?? "Not requested"]],
actions: fault.canReset && fault.resetStatus !== "pending" ? [{
label: "Request reset", command: { type: "request-reset", faultId: fault.id },
confirmation: `Request a reset of ${fault.charger}? The fault remains open until the charger reports recovery.`,
}] : [],
})) : null;
return <WidgetOperations title="Open Faults" icon={<BatteryWarning />} size="small" description={data?.network} rows={rows}
empty="No open faults" onAction={action} summary={rows && <><strong>{rows.length}</strong><span>open · {data?.faults.filter(fault => fault.severity === "critical").length ?? 0} critical</span></>} />;
}
lucide-reactmotionreactreact-dom