fix: warn abount unsupported charging profiles structure
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 25 Jul 2023 21:13:17 +0000 (23:13 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 25 Jul 2023 21:13:17 +0000 (23:13 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStationUtils.ts

index de29639b719888a7315edf3ef89ebd51c7e2cf29..0eeb205189456c4d0ea44ec96d3cfdf434722075 100644 (file)
@@ -731,6 +731,12 @@ const getLimitFromChargingProfiles = (
     ) {
       chargingSchedule.startSchedule = connectorStatus?.transactionStart;
     }
+    if (isNullOrUndefined(chargingSchedule?.duration)) {
+      logger.error(
+        `${logPrefix} ${moduleName}.getLimitFromChargingProfiles: Charging profile id ${chargingProfile.chargingProfileId} has no duration defined, not yet supported`,
+      );
+      continue;
+    }
     // Check if the charging profile is active
     if (
       isValidDate(chargingSchedule?.startSchedule) &&
@@ -891,7 +897,19 @@ const checkRecurringChargingProfileDuration = (
   interval: Interval,
   logPrefix: string,
 ) => {
-  if (
+  if (isNullOrUndefined(chargingProfile.chargingSchedule.duration)) {
+    logger.warn(
+      `${logPrefix} ${moduleName}.checkRecurringChargingProfileDuration: Recurring ${
+        chargingProfile.chargingProfileKind
+      } charging profile id ${
+        chargingProfile.chargingProfileId
+      } duration is not defined, set it to the recurrency time interval duration ${differenceInSeconds(
+        interval.end,
+        interval.start,
+      )}`,
+    );
+    chargingProfile.chargingSchedule.duration = differenceInSeconds(interval.end, interval.start);
+  } else if (
     chargingProfile.chargingSchedule.duration! > differenceInSeconds(interval.end, interval.start)
   ) {
     logger.warn(