Dependencies update.
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / 1.6 / OCCP16IncomingRequestService.ts
index 0425c58ced76e706a19e9562d7c9866844dbd649..a63a28e4b875e0d0c97bc05f6b3c2152891dcc13 100644 (file)
@@ -40,10 +40,11 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
 
   // Simulate charging station restart
   private handleRequestReset(commandPayload: ResetRequest): DefaultResponse {
-    setImmediate(async () => {
+    // eslint-disable-next-line @typescript-eslint/no-misused-promises
+    setImmediate(async (): Promise<void> => {
       await this.chargingStation.stop(commandPayload.type + 'Reset' as OCPP16StopTransactionReason);
       await Utils.sleep(this.chargingStation.stationInfo.resetTime);
-      await this.chargingStation.start();
+      this.chargingStation.start();
     });
     logger.info(`${this.chargingStation.logPrefix()} ${commandPayload.type} reset command received, simulating it. The station will be back online in ${Utils.milliSecondsToHHMMSS(this.chargingStation.stationInfo.resetTime)}`);
     return Constants.OCPP_RESPONSE_ACCEPTED;
@@ -169,6 +170,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
       return Constants.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED;
     }
     this.chargingStation.setChargingProfile(commandPayload.connectorId, commandPayload.csChargingProfiles);
+    logger.debug(`${this.chargingStation.logPrefix()} Charging profile set, dump their stack: %j`, this.chargingStation.getConnector(commandPayload.connectorId).chargingProfiles);
     return Constants.OCPP_SET_CHARGING_PROFILE_RESPONSE_ACCEPTED;
   }
 
@@ -179,6 +181,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
     }
     if (commandPayload.connectorId && !Utils.isEmptyArray(this.chargingStation.getConnector(commandPayload.connectorId).chargingProfiles)) {
       this.chargingStation.getConnector(commandPayload.connectorId).chargingProfiles = [];
+      logger.debug(`${this.chargingStation.logPrefix()} Charging profiles cleared, dump their stack: %j`, this.chargingStation.getConnector(commandPayload.connectorId).chargingProfiles);
       return Constants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_ACCEPTED;
     }
     if (!commandPayload.connectorId) {
@@ -201,6 +204,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
             }
             if (clearCurrentCP) {
               this.chargingStation.getConnector(commandPayload.connectorId).chargingProfiles[index] = {} as OCPP16ChargingProfile;
+              logger.debug(`${this.chargingStation.logPrefix()} Charging profiles cleared, dump their stack: %j`, this.chargingStation.getConnector(commandPayload.connectorId).chargingProfiles);
               clearedCP = true;
             }
           });
@@ -213,7 +217,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
     return Constants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN;
   }
 
-  private handleRequestChangeAvailability(commandPayload: ChangeAvailabilityRequest): ChangeAvailabilityResponse {
+  private async handleRequestChangeAvailability(commandPayload: ChangeAvailabilityRequest): Promise<ChangeAvailabilityResponse> {
     const connectorId: number = commandPayload.connectorId;
     if (!this.chargingStation.getConnector(connectorId)) {
       logger.error(`${this.chargingStation.logPrefix()} Trying to change the availability of a non existing connector Id ${connectorId.toString()}`);
@@ -228,7 +232,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
         }
         this.chargingStation.getConnector(Utils.convertToInt(connector)).availability = commandPayload.type;
         if (response === Constants.OCPP_AVAILABILITY_RESPONSE_ACCEPTED) {
-          void this.chargingStation.ocppRequestService.sendStatusNotification(Utils.convertToInt(connector), chargePointStatus);
+          await this.chargingStation.ocppRequestService.sendStatusNotification(Utils.convertToInt(connector), chargePointStatus);
           this.chargingStation.getConnector(Utils.convertToInt(connector)).status = chargePointStatus;
         }
       }
@@ -239,7 +243,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
         return Constants.OCPP_AVAILABILITY_RESPONSE_SCHEDULED;
       }
       this.chargingStation.getConnector(connectorId).availability = commandPayload.type;
-      void this.chargingStation.ocppRequestService.sendStatusNotification(connectorId, chargePointStatus);
+      await this.chargingStation.ocppRequestService.sendStatusNotification(connectorId, chargePointStatus);
       this.chargingStation.getConnector(connectorId).status = chargePointStatus;
       return Constants.OCPP_AVAILABILITY_RESPONSE_ACCEPTED;
     }
@@ -256,6 +260,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
           this.chargingStation.getConnector(transactionConnectorID).status = OCPP16ChargePointStatus.PREPARING;
           if (commandPayload.chargingProfile && commandPayload.chargingProfile.chargingProfilePurpose === ChargingProfilePurposeType.TX_PROFILE) {
             this.chargingStation.setChargingProfile(transactionConnectorID, commandPayload.chargingProfile);
+            logger.debug(`${this.chargingStation.logPrefix()} Charging profile set at start transaction, dump their stack: %j`, this.chargingStation.getConnector(transactionConnectorID).chargingProfiles);
           } else if (commandPayload.chargingProfile && commandPayload.chargingProfile.chargingProfilePurpose !== ChargingProfilePurposeType.TX_PROFILE) {
             return Constants.OCPP_RESPONSE_REJECTED;
           }
@@ -271,6 +276,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
       this.chargingStation.getConnector(transactionConnectorID).status = OCPP16ChargePointStatus.PREPARING;
       if (commandPayload.chargingProfile && commandPayload.chargingProfile.chargingProfilePurpose === ChargingProfilePurposeType.TX_PROFILE) {
         this.chargingStation.setChargingProfile(transactionConnectorID, commandPayload.chargingProfile);
+        logger.debug(`${this.chargingStation.logPrefix()} Charging profile set at start transaction, dump their stack: %j`, this.chargingStation.getConnector(commandPayload.connectorId).chargingProfiles);
       } else if (commandPayload.chargingProfile && commandPayload.chargingProfile.chargingProfilePurpose !== ChargingProfilePurposeType.TX_PROFILE) {
         return Constants.OCPP_RESPONSE_REJECTED;
       }