Set connector status at start given its availability first
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 2 Oct 2022 17:23:10 +0000 (19:23 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 2 Oct 2022 17:23:10 +0000 (19:23 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts

index 05ef9252e93b096d074cec55e565737451459a66..7853d10ed8fc6b5d3bc58737bd3172c20fb581c9 100644 (file)
@@ -535,19 +535,6 @@ export default class ChargingStation {
       if (this.stopping === false) {
         this.stopping = true;
         await this.stopMessageSequence(reason);
-        for (const connectorId of this.connectors.keys()) {
-          if (connectorId > 0) {
-            await this.ocppRequestService.requestHandler<
-              StatusNotificationRequest,
-              StatusNotificationResponse
-            >(this, RequestCommand.STATUS_NOTIFICATION, {
-              connectorId,
-              status: ChargePointStatus.UNAVAILABLE,
-              errorCode: ChargePointErrorCode.NO_ERROR,
-            });
-            this.getConnectorStatus(connectorId).status = null;
-          }
-        }
         this.closeWSConnection();
         this.wsConnectionRestarted = false;
         if (this.getEnableStatistics()) {
@@ -1775,12 +1762,6 @@ export default class ChargingStation {
       let chargePointStatus: ChargePointStatus;
       if (connectorId === 0) {
         continue;
-      } else if (
-        !this.getConnectorStatus(connectorId)?.status &&
-        this.getConnectorStatus(connectorId)?.bootStatus
-      ) {
-        // Set boot status in template at startup
-        chargePointStatus = this.getConnectorStatus(connectorId).bootStatus;
       } else if (
         !this.getConnectorStatus(connectorId)?.status &&
         (this.isChargingStationAvailable() === false ||
@@ -1788,6 +1769,12 @@ export default class ChargingStation {
             this.isConnectorAvailable(connectorId) === false))
       ) {
         chargePointStatus = ChargePointStatus.UNAVAILABLE;
+      } else if (
+        !this.getConnectorStatus(connectorId)?.status &&
+        this.getConnectorStatus(connectorId)?.bootStatus
+      ) {
+        // Set boot status in template at startup
+        chargePointStatus = this.getConnectorStatus(connectorId).bootStatus;
       } else if (this.getConnectorStatus(connectorId)?.status) {
         // Set previous status at startup
         chargePointStatus = this.getConnectorStatus(connectorId).status;
@@ -1825,6 +1812,19 @@ export default class ChargingStation {
     } else {
       await this.stopRunningTransactions(reason);
     }
+    for (const connectorId of this.connectors.keys()) {
+      if (connectorId > 0) {
+        await this.ocppRequestService.requestHandler<
+          StatusNotificationRequest,
+          StatusNotificationResponse
+        >(this, RequestCommand.STATUS_NOTIFICATION, {
+          connectorId,
+          status: ChargePointStatus.UNAVAILABLE,
+          errorCode: ChargePointErrorCode.NO_ERROR,
+        });
+        this.getConnectorStatus(connectorId).status = null;
+      }
+    }
   }
 
   private startWebSocketPing(): void {