From 142a66c9948adf165706107e1fcadf9f87bae559 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 25 Jul 2023 23:13:17 +0200 Subject: [PATCH] fix: warn abount unsupported charging profiles structure MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStationUtils.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 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( -- 2.34.1