feat: add connector status handling at boot with evses configuration
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 28 Apr 2023 13:27:49 +0000 (15:27 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 28 Apr 2023 13:27:49 +0000 (15:27 +0200)
Reference: https://github.com/SAP/e-mobility-charging-stations-simulator/issues/349

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/ChargingStationUtils.ts

index 70f511e0878c6d16944f046dde834c73d2fdc4b7..c51064f6667c74de7624a062e09546ed1191b7d8 100644 (file)
@@ -1997,30 +1997,32 @@ export class ChargingStation {
     // Start heartbeat
     this.startHeartbeat();
     // Initialize connectors status
-    for (const connectorId of this.connectors.keys()) {
-      let connectorStatus: ConnectorStatusEnum | undefined;
-      if (connectorId === 0) {
-        continue;
-      } else if (
-        !this.getConnectorStatus(connectorId)?.status &&
-        (this.isChargingStationAvailable() === false ||
-          this.isConnectorAvailable(connectorId) === false)
-      ) {
-        connectorStatus = ConnectorStatusEnum.Unavailable;
-      } else if (
-        !this.getConnectorStatus(connectorId)?.status &&
-        this.getConnectorStatus(connectorId)?.bootStatus
-      ) {
-        // Set boot status in template at startup
-        connectorStatus = this.getConnectorStatus(connectorId)?.bootStatus;
-      } else if (this.getConnectorStatus(connectorId)?.status) {
-        // Set previous status at startup
-        connectorStatus = this.getConnectorStatus(connectorId)?.status;
-      } else {
-        // Set default status
-        connectorStatus = ConnectorStatusEnum.Available;
+    if (this.hasEvses) {
+      for (const [evseId, evseStatus] of this.evses) {
+        if (evseId === 0) {
+          continue;
+        }
+        for (const [connectorId, connectorStatus] of evseStatus.connectors) {
+          const connectorBootStatus = ChargingStationUtils.getBootConnectorStatus(
+            this,
+            connectorId,
+            connectorStatus
+          );
+          await OCPPServiceUtils.sendAndSetConnectorStatus(this, connectorId, connectorBootStatus);
+        }
+      }
+    } else {
+      for (const connectorId of this.connectors.keys()) {
+        if (connectorId === 0) {
+          continue;
+        }
+        const connectorBootStatus = ChargingStationUtils.getBootConnectorStatus(
+          this,
+          connectorId,
+          this.getConnectorStatus(connectorId)
+        );
+        await OCPPServiceUtils.sendAndSetConnectorStatus(this, connectorId, connectorBootStatus);
       }
-      await OCPPServiceUtils.sendAndSetConnectorStatus(this, connectorId, connectorStatus);
     }
     if (this.stationInfo?.firmwareStatus === FirmwareStatus.Installing) {
       await this.ocppRequestService.requestHandler<
index 49a61101533043ae15cb09c6783eb197bf452cfd..4564f389674f45e4dba051e2bf0432e8db11dafa 100644 (file)
@@ -19,6 +19,7 @@ import {
   type ChargingStationInfo,
   type ChargingStationTemplate,
   type ConnectorStatus,
+  ConnectorStatusEnum,
   CurrentType,
   type EvseTemplate,
   type OCPP16BootNotificationRequest,
@@ -125,6 +126,31 @@ export class ChargingStationUtils {
     }
   }
 
+  public static getBootConnectorStatus(
+    chargingStation: ChargingStation,
+    connectorId: number,
+    connectorStatus: ConnectorStatus
+  ): ConnectorStatusEnum {
+    let connectorBootStatus: ConnectorStatusEnum;
+    if (
+      !connectorStatus?.status &&
+      (chargingStation.isChargingStationAvailable() === false ||
+        chargingStation.isConnectorAvailable(connectorId) === false)
+    ) {
+      connectorBootStatus = ConnectorStatusEnum.Unavailable;
+    } else if (!connectorStatus?.status && connectorStatus?.bootStatus) {
+      // Set boot status in template at startup
+      connectorBootStatus = connectorStatus?.bootStatus;
+    } else if (connectorStatus?.status) {
+      // Set previous status at startup
+      connectorBootStatus = connectorStatus?.status;
+    } else {
+      // Set default status
+      connectorBootStatus = ConnectorStatusEnum.Available;
+    }
+    return connectorBootStatus;
+  }
+
   public static getConfiguredNumberOfConnectors(stationInfo: ChargingStationInfo): number {
     let configuredMaxConnectors: number;
     if (Utils.isNotEmptyArray(stationInfo.numberOfConnectors) === true) {