From: Jérôme Benoit Date: Tue, 25 Jul 2023 21:13:17 +0000 (+0200) Subject: fix: warn abount unsupported charging profiles structure X-Git-Tag: v1.2.20~139 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=142a66c9948adf165706107e1fcadf9f87bae559;p=e-mobility-charging-stations-simulator.git fix: warn abount unsupported charging profiles structure Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index de29639b..0eeb2051 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -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(