Fix charging station initial registration at boot notification
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 7 Feb 2022 10:16:59 +0000 (11:16 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 7 Feb 2022 10:16:59 +0000 (11:16 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/ocpp/OCPPRequestService.ts

index 99e8f5ee6aaf91b923c8da8d491e4ba383381e12..488333379b3f847ef6749efc70fcbb10e46577ce 100644 (file)
@@ -123,6 +123,10 @@ export default class ChargingStation {
     return this?.wsConnection?.readyState === OPEN;
   }
 
+  public isInUnknownState(): boolean {
+    return Utils.isNullOrUndefined(this?.bootNotificationResponse?.status);
+  }
+
   public isInPendingState(): boolean {
     return this?.bootNotificationResponse?.status === RegistrationStatus.PENDING;
   }
@@ -136,7 +140,7 @@ export default class ChargingStation {
   }
 
   public isRegistered(): boolean {
-    return this.isInAcceptedState() || this.isInPendingState();
+    return !this.isInUnknownState() && (this.isInAcceptedState() || this.isInPendingState());
   }
 
   public isChargingStationAvailable(): boolean {
index 14cab283366c96b64cd61bf7970251ae2c0f43c8..af116c4ec92acb366230c54fb1cdd4c181a584fa 100644 (file)
@@ -32,7 +32,8 @@ export default abstract class OCPPRequestService {
       }): Promise<JsonType | OCPPError | string> {
     if (this.chargingStation.isInRejectedState() || (this.chargingStation.isInPendingState() && !params.triggerMessage)) {
       throw new OCPPError(ErrorType.SECURITY_ERROR, 'Cannot send command payload if the charging station is not in accepted state', commandName);
-    } else if (this.chargingStation.isInAcceptedState() || (this.chargingStation.isInPendingState() && params.triggerMessage)) {
+    } else if ((this.chargingStation.isInUnknownState() && commandName === RequestCommand.BOOT_NOTIFICATION)
+      || this.chargingStation.isInAcceptedState() || (this.chargingStation.isInPendingState() && params.triggerMessage)) {
       // eslint-disable-next-line @typescript-eslint/no-this-alias
       const self = this;
       // Send a message through wsConnection