fix: ensure the latest schedule period within the charging profile
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / 1.6 / OCPP16ServiceUtils.ts
index 6765722c9b28b0276f592b03aacf02236759c44c..222406c6ce84090f5b82fc1af5e5b7d3d783c2d1 100644 (file)
@@ -863,7 +863,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
       Array.isArray(chargingStation.getConnectorStatus(connectorId)?.chargingProfiles) === false
     ) {
       logger.error(
-        `${chargingStation.logPrefix()} Trying to set a charging profile on connector id ${connectorId} with an improper attribute type for the charging profiles array, applying proper type initialization`,
+        `${chargingStation.logPrefix()} Trying to set a charging profile on connector id ${connectorId} with an improper attribute type for the charging profiles array, applying proper type deferred initialization`,
       );
       chargingStation.getConnectorStatus(connectorId)!.chargingProfiles = [];
     }
@@ -890,28 +890,23 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
     commandPayload: ClearChargingProfileRequest,
     chargingProfiles: OCPP16ChargingProfile[] | undefined,
   ): boolean => {
+    const { id, chargingProfilePurpose, stackLevel } = commandPayload;
     let clearedCP = false;
     if (isNotEmptyArray(chargingProfiles)) {
       chargingProfiles?.forEach((chargingProfile: OCPP16ChargingProfile, index: number) => {
         let clearCurrentCP = false;
-        if (chargingProfile.chargingProfileId === commandPayload.id) {
+        if (chargingProfile.chargingProfileId === id) {
           clearCurrentCP = true;
         }
-        if (
-          !commandPayload.chargingProfilePurpose &&
-          chargingProfile.stackLevel === commandPayload.stackLevel
-        ) {
+        if (!chargingProfilePurpose && chargingProfile.stackLevel === stackLevel) {
           clearCurrentCP = true;
         }
-        if (
-          !chargingProfile.stackLevel &&
-          chargingProfile.chargingProfilePurpose === commandPayload.chargingProfilePurpose
-        ) {
+        if (!stackLevel && chargingProfile.chargingProfilePurpose === chargingProfilePurpose) {
           clearCurrentCP = true;
         }
         if (
-          chargingProfile.stackLevel === commandPayload.stackLevel &&
-          chargingProfile.chargingProfilePurpose === commandPayload.chargingProfilePurpose
+          chargingProfile.stackLevel === stackLevel &&
+          chargingProfile.chargingProfilePurpose === chargingProfilePurpose
         ) {
           clearCurrentCP = true;
         }