Fix PENDING state boot notification handling
[e-mobility-charging-stations-simulator.git] / src / charging-station / ChargingStation.ts
index 4f6c7771283f865bb44d700541fb5fe42e0fbf36..018a6fbeea98fa780b522a2d08c1218011aa6c7f 100644 (file)
@@ -122,10 +122,22 @@ export default class ChargingStation {
     return this?.wsConnection?.readyState === OPEN;
   }
 
-  public isRegistered(): boolean {
+  public isInPendingState(): boolean {
+    return this?.bootNotificationResponse?.status === RegistrationStatus.PENDING;
+  }
+
+  public isInAcceptedState(): boolean {
     return this?.bootNotificationResponse?.status === RegistrationStatus.ACCEPTED;
   }
 
+  public isInRejectedState(): boolean {
+    return this?.bootNotificationResponse?.status === RegistrationStatus.REJECTED;
+  }
+
+  public isRegistered(): boolean {
+    return this.isInAcceptedState() || this.isInPendingState();
+  }
+
   public isChargingStationAvailable(): boolean {
     return this.getConnectorStatus(0).availability === AvailabilityType.OPERATIVE;
   }
@@ -644,12 +656,22 @@ export default class ChargingStation {
       await this.ocppRequestService.sendBootNotification(this.bootNotificationRequest.chargePointModel,
         this.bootNotificationRequest.chargePointVendor, this.bootNotificationRequest.chargeBoxSerialNumber, this.bootNotificationRequest.firmwareVersion);
     }
-    if (this.isRegistered()) {
+    if (this.isInAcceptedState()) {
       await this.startMessageSequence();
       this.stopped && (this.stopped = false);
       if (this.wsConnectionRestarted && this.isWebSocketConnectionOpened()) {
         this.flushMessageBuffer();
       }
+    } else if (this.isInPendingState()) {
+      // The central server shall issue a triggerMessage to the charging station for the boot notification at the end of its configuration process
+      while (!this.isInAcceptedState()) {
+        await this.startMessageSequence();
+        this.stopped && (this.stopped = false);
+        if (this.wsConnectionRestarted && this.isWebSocketConnectionOpened()) {
+          this.flushMessageBuffer();
+        }
+        await Utils.sleep(Constants.CHARGING_STATION_DEFAULT_START_SEQUENCE_DELAY);
+      }
     } else {
       logger.error(`${this.logPrefix()} Registration failure: max retries reached (${this.getRegistrationMaxRetries()}) or retry disabled (${this.getRegistrationMaxRetries()})`);
     }
@@ -972,7 +994,7 @@ export default class ChargingStation {
           }
           break;
         default:
-          logger.error(`${this.logPrefix()} Unknown supervision url distribution '${Configuration.getSupervisionUrlDistribution()}', defaulting to ${SupervisionUrlDistribution.ROUND_ROBIN}`);
+          logger.error(`${this.logPrefix()} Unknown supervision url distribution '${Configuration.getSupervisionUrlDistribution()}' from values '${SupervisionUrlDistribution.toString()}', defaulting to ${SupervisionUrlDistribution.ROUND_ROBIN}`);
           urlIndex = (this.index - 1) % supervisionUrls.length;
           break;
       }