From: Jérôme Benoit Date: Tue, 25 Jul 2023 16:32:41 +0000 (+0200) Subject: fix: ensure recurring profile duration is valid X-Git-Tag: v1.2.20~146 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=55f2ab602b8b52836cbf267e960b7c11633a2e97;p=e-mobility-charging-stations-simulator.git fix: ensure recurring profile duration is valid Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index fa7263e0..b26f9970 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -736,7 +736,14 @@ const getLimitFromChargingProfiles = ( isAfter(addSeconds(chargingSchedule.startSchedule!, chargingSchedule.duration!), currentDate) ) { if (isNotEmptyArray(chargingSchedule.chargingSchedulePeriod)) { - // Handling of only one schedule period + chargingSchedule.chargingSchedulePeriod.sort((a, b) => a.startPeriod - b.startPeriod); + if (chargingSchedule.chargingSchedulePeriod[0].startPeriod !== 0) { + logger.error( + `${logPrefix} ${moduleName}.getLimitFromChargingProfiles: Charging profile id ${chargingProfile.chargingProfileId} first schedule period start period ${chargingSchedule.chargingSchedulePeriod[0].startPeriod} is not equal to 0`, + ); + // continue; + } + // Handling of only one schedule period with startPeriod = 0 if ( chargingSchedule.chargingSchedulePeriod.length === 1 && chargingSchedule.chargingSchedulePeriod[0].startPeriod === 0 @@ -748,7 +755,6 @@ const getLimitFromChargingProfiles = ( logger.debug(debugLogMsg, result); return result; } - chargingSchedule.chargingSchedulePeriod.sort((a, b) => a.startPeriod - b.startPeriod); let lastButOneSchedule: ChargingSchedulePeriod | undefined; // Search for the right schedule period for (const schedulePeriod of chargingSchedule.chargingSchedulePeriod) { @@ -876,6 +882,7 @@ const checkRecurringChargingProfileDuration = ( interval.start, )}`, ); + chargingProfile.chargingSchedule.duration = differenceInSeconds(interval.end, interval.start); } }; diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 82647835..c7337ab6 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -979,20 +979,26 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { private setRemoteStartTransactionChargingProfile( chargingStation: ChargingStation, connectorId: number, - cp: OCPP16ChargingProfile, + chargingProfile: OCPP16ChargingProfile, ): boolean { - if (cp && cp.chargingProfilePurpose === OCPP16ChargingProfilePurposeType.TX_PROFILE) { - OCPP16ServiceUtils.setChargingProfile(chargingStation, connectorId, cp); + if ( + chargingProfile && + chargingProfile.chargingProfilePurpose === OCPP16ChargingProfilePurposeType.TX_PROFILE + ) { + OCPP16ServiceUtils.setChargingProfile(chargingStation, connectorId, chargingProfile); logger.debug( `${chargingStation.logPrefix()} Charging profile(s) set at remote start transaction on connector id ${connectorId}: %j`, - cp, + chargingProfile, ); return true; - } else if (cp && cp.chargingProfilePurpose !== OCPP16ChargingProfilePurposeType.TX_PROFILE) { + } else if ( + chargingProfile && + chargingProfile.chargingProfilePurpose !== OCPP16ChargingProfilePurposeType.TX_PROFILE + ) { logger.warn( `${chargingStation.logPrefix()} Not allowed to set ${ - cp.chargingProfilePurpose + chargingProfile.chargingProfilePurpose } charging profile(s) at remote start transaction`, ); return false;