Unify charge point command channel status

This commit is contained in:
2026-03-18 15:26:56 +08:00
parent 3508e7de19
commit 2c90404637
14 changed files with 347 additions and 86 deletions

View File

@@ -26,7 +26,8 @@ import { Clock, EvCharger, Plug, Zap } from "lucide-react";
type ConnectionStatus = "online" | "stale" | "offline";
function getStatus(cp: ChargePoint, connected: string[]): ConnectionStatus {
if (!connected.includes(cp.chargePointIdentifier)) return "offline";
if (cp.transportStatus === "unavailable") return "stale";
if (cp.transportStatus !== "online" || !connected.includes(cp.chargePointIdentifier)) return "offline";
if (!cp.lastHeartbeatAt) return "stale";
return dayjs().diff(dayjs(cp.lastHeartbeatAt), "minute") < 5 ? "online" : "stale";
}
@@ -36,7 +37,7 @@ const STATUS_CONFIG: Record<
{ color: string; edgeColor: string; label: string; animated: boolean }
> = {
online: { color: "#22c55e", edgeColor: "#22c55e", label: "在线", animated: true },
stale: { color: "#f59e0b", edgeColor: "#f59e0b", label: "心跳超时", animated: true },
stale: { color: "#f59e0b", edgeColor: "#f59e0b", label: "通道异常", animated: true },
offline: { color: "#71717a", edgeColor: "#9ca3af", label: "离线", animated: false },
};