kirby-ocpp 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -88,6 +88,7 @@ Global shortcuts:
88
88
  - `q`: quit.
89
89
 
90
90
  Forms prompt for values such as `idTag`, connector id, measurands, and `DataTransfer` payloads. There is no built-in default RFID/idTag.
91
+ On the Connector tab, `s` cycles the selected connector status and `S` opens a list of all OCPP connector statuses.
91
92
 
92
93
  ## Persistence
93
94
 
@@ -54,9 +54,14 @@ export class OcppClient extends EventEmitter {
54
54
  }
55
55
  this.rejectPending(new Error("Connection closed"));
56
56
  this.stopPingTimer();
57
- this.socket.removeAllListeners();
58
- if (this.socket.readyState === WebSocket.OPEN || this.socket.readyState === WebSocket.CONNECTING) {
59
- this.socket.close();
57
+ const socket = this.socket;
58
+ socket.removeAllListeners();
59
+ socket.on("error", () => { });
60
+ if (socket.readyState === WebSocket.OPEN) {
61
+ socket.close();
62
+ }
63
+ else if (socket.readyState === WebSocket.CONNECTING) {
64
+ socket.terminate();
60
65
  }
61
66
  this.socket = undefined;
62
67
  }
package/dist/station.d.ts CHANGED
@@ -57,6 +57,7 @@ export declare class Station extends EventEmitter {
57
57
  setDiagnosticsOutcome(outcome: DiagnosticsOutcome): void;
58
58
  setFirmwareOutcome(outcome: FirmwareOutcome): void;
59
59
  cycleStatus(connectorId?: number): Promise<void>;
60
+ setStatus(connectorId: number | undefined, status: ConnectorStatus): Promise<void>;
60
61
  addConnector(): number;
61
62
  private bindClientEvents;
62
63
  private handleCentralSystemCall;
package/dist/station.js CHANGED
@@ -495,14 +495,17 @@ export class Station extends EventEmitter {
495
495
  async cycleStatus(connectorId = this.config.connectorId) {
496
496
  const connector = this.connectors.get(connectorId);
497
497
  const next = nextConnectorStatus(connector.status);
498
+ await this.setStatus(connectorId, next);
499
+ }
500
+ async setStatus(connectorId = this.config.connectorId, status) {
498
501
  this.connectors.patch(connectorId, {
499
- status: next,
500
- errorCode: next === "Faulted" ? "OtherError" : "NoError",
501
- info: next === "Faulted" ? "Manual fault" : undefined,
502
- vendorId: next === "Faulted" ? this.config.vendor : undefined,
502
+ status,
503
+ errorCode: status === "Faulted" ? "OtherError" : "NoError",
504
+ info: status === "Faulted" ? "Manual fault" : undefined,
505
+ vendorId: status === "Faulted" ? this.config.vendor : undefined,
503
506
  vendorErrorCode: undefined
504
507
  });
505
- await this.statusNotification(connectorId, next);
508
+ await this.statusNotification(connectorId, status);
506
509
  }
507
510
  addConnector() {
508
511
  const { id: nextId } = this.connectors.add();
package/dist/tui.d.ts CHANGED
@@ -49,6 +49,7 @@ export declare class Tui {
49
49
  private tabLabel;
50
50
  private togglePlug;
51
51
  private stopTransactionFlow;
52
+ private setStatusFlow;
52
53
  private startTransactionFlow;
53
54
  private customMeterValuesFlow;
54
55
  private dataTransferFlow;
package/dist/tui.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { spawnSync } from "node:child_process";
2
2
  import blessed from "blessed";
3
+ import { CONNECTOR_STATUS_SEQUENCE } from "./station/connector-status.js";
3
4
  const TABS = [
4
5
  { id: "station", label: "Station" },
5
6
  { id: "connector", label: "Connector" },
@@ -394,6 +395,7 @@ export class Tui {
394
395
  return [
395
396
  action("p", "Plug / unplug EV", "Toggle EV plug state on the selected connector.", () => this.togglePlug()),
396
397
  action("s", "Cycle status", "Cycle StatusNotification status on the selected connector.", () => this.runStationTask(() => this.station.cycleStatus(this.selectedConnectorId))),
398
+ action("S", "Set status", "Choose any StatusNotification status for the selected connector.", () => this.setStatusFlow()),
397
399
  action("n", "Send StatusNotification", "Send current selected connector status now.", () => this.runStationTask(() => this.station.statusNotification(this.selectedConnectorId, this.selectedConnector()?.status, true))),
398
400
  action("f", "Fault / clear fault", "Inject or clear a fault on the selected connector.", () => this.faultFlow()),
399
401
  action("]", "Next connector", "Select next connector.", () => this.selectNextConnector()),
@@ -460,6 +462,8 @@ export class Tui {
460
462
  "d",
461
463
  "D",
462
464
  "S-d",
465
+ "S",
466
+ "S-s",
463
467
  "e",
464
468
  "f",
465
469
  "h",
@@ -798,6 +802,9 @@ export class Tui {
798
802
  stopTransactionFlow() {
799
803
  this.promptChoice("StopTransaction reason", STOP_REASONS, (reason) => this.runStationTask(() => this.station.stopTransaction(this.selectedConnectorId, readStopReason(reason), this.selectedConnector()?.lastIdTag)));
800
804
  }
805
+ setStatusFlow() {
806
+ this.promptChoice("Connector status", CONNECTOR_STATUS_SEQUENCE, (status) => this.runStationTask(() => this.station.setStatus(this.selectedConnectorId, readConnectorStatus(status))));
807
+ }
801
808
  startTransactionFlow() {
802
809
  this.promptForm("StartTransaction", [
803
810
  { name: "connectorId", label: "connectorId", initialValue: String(this.selectedConnectorId) },
@@ -1432,6 +1439,10 @@ function readStopReason(value) {
1432
1439
  const normalized = value.trim();
1433
1440
  return isStopReason(normalized) ? normalized : "Local";
1434
1441
  }
1442
+ function readConnectorStatus(value) {
1443
+ const normalized = value.trim();
1444
+ return isConnectorStatus(normalized) ? normalized : "Available";
1445
+ }
1435
1446
  function parseObjectJson(value) {
1436
1447
  try {
1437
1448
  const parsed = JSON.parse(value);
@@ -1503,6 +1514,9 @@ function normalizeActionKey(keyName) {
1503
1514
  if (keyName === "S-d") {
1504
1515
  return "D";
1505
1516
  }
1517
+ if (keyName === "S-s") {
1518
+ return "S";
1519
+ }
1506
1520
  if (keyName === "S-u") {
1507
1521
  return "U";
1508
1522
  }
@@ -1515,7 +1529,7 @@ function legacyActionTab(key) {
1515
1529
  if (["b", "h", "x"].includes(key)) {
1516
1530
  return "station";
1517
1531
  }
1518
- if (["p", "s", "n", "f"].includes(key)) {
1532
+ if (["p", "s", "S", "n", "f"].includes(key)) {
1519
1533
  return "connector";
1520
1534
  }
1521
1535
  if (["a", "t", "e", "m", "M"].includes(key)) {
@@ -1554,6 +1568,9 @@ const STOP_REASONS = [
1554
1568
  function isStopReason(value) {
1555
1569
  return STOP_REASONS.includes(value);
1556
1570
  }
1571
+ function isConnectorStatus(value) {
1572
+ return CONNECTOR_STATUS_SEQUENCE.includes(value);
1573
+ }
1557
1574
  const CHARGE_POINT_ERROR_CODES = [
1558
1575
  "ConnectorLockFailure",
1559
1576
  "EVCommunicationError",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kirby-ocpp",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "A terminal OCPP charge point emulator.",
5
5
  "type": "module",
6
6
  "author": "archhaze24",