Add charging station instance id
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / OCPPRequestService.ts
index 14cab283366c96b64cd61bf7970251ae2c0f43c8..da8870292d0d4d3751a11992e473dc05f06b2de5 100644 (file)
@@ -30,9 +30,9 @@ export default abstract class OCPPRequestService {
         skipBufferingOnError: false,
         triggerMessage: false
       }): 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)) {
+    if ((this.chargingStation.isInUnknownState() && commandName === RequestCommand.BOOT_NOTIFICATION)
+      || (!this.chargingStation.getOcppStrictCompliance() && this.chargingStation.isInUnknownState())
+      || 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
@@ -106,13 +106,12 @@ export default abstract class OCPPRequestService {
       }), Constants.OCPP_WEBSOCKET_TIMEOUT, new OCPPError(ErrorType.GENERIC_ERROR, `Timeout for message id '${messageId}'`, commandName, messageData?.details as JsonType ?? {}), () => {
         messageType === MessageType.CALL_MESSAGE && this.chargingStation.requests.delete(messageId);
       });
-    } else {
-      throw new OCPPError(ErrorType.SECURITY_ERROR, 'Cannot send command payload if the charging station is in unknown state', commandName);
     }
+    throw new OCPPError(ErrorType.SECURITY_ERROR, `Cannot send command ${commandName} payload when the charging station is in ${this.chargingStation.getRegistrationStatus()} state on the central server`, commandName);
   }
 
   protected handleRequestError(commandName: RequestCommand, error: Error): void {
-    logger.error(this.chargingStation.logPrefix() + ' Request command ' + commandName + ' error: %j', error);
+    logger.error(this.chargingStation.logPrefix() + ' Request command %s error: %j', commandName, error);
     throw error;
   }