Fix request and response handling in all registration state
[e-mobility-charging-stations-simulator.git] / src / charging-station / ChargingStation.ts
index 565bdb895af476237584c66c86a6592d4c0e9772..6be15b83e980656b237a7a1586078134dd17ae54 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,7 +656,17 @@ 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 Utils.sleep(Constants.CHARGING_STATION_DEFAULT_START_SEQUENCE_DELAY);
+      }
       await this.startMessageSequence();
       this.stopped && (this.stopped = false);
       if (this.wsConnectionRestarted && this.isWebSocketConnectionOpened()) {