- const startDate = new Date();
- const endDate = new Date(startDate.getTime() + secondsToMilliseconds(commandPayload.duration));
- let compositeSchedule: OCPP16ChargingSchedule | undefined;
- for (const chargingProfile of chargingStation.getConnectorStatus(commandPayload.connectorId)!
- .chargingProfiles!) {
- // FIXME: build the composite schedule including the local power limit, the stack level, the charging rate unit, etc.
+ const currentDate = new Date();
+ const interval: Interval = {
+ start: currentDate,
+ end: addSeconds(currentDate, duration),
+ };
+ const chargingProfiles: OCPP16ChargingProfile[] = [];
+ for (const chargingProfile of cloneObject<OCPP16ChargingProfile[]>(
+ (connectorStatus?.chargingProfiles ?? []).concat(
+ chargingStation.getConnectorStatus(0)?.chargingProfiles ?? [],
+ ),
+ ).sort((a, b) => b.stackLevel - a.stackLevel)) {
+ if (
+ connectorStatus?.transactionStarted &&
+ isNullOrUndefined(chargingProfile.chargingSchedule?.startSchedule)
+ ) {
+ logger.debug(
+ `${chargingStation.logPrefix()} ${moduleName}.handleRequestGetCompositeSchedule: Charging profile id ${
+ chargingProfile.chargingProfileId
+ } has no startSchedule defined. Trying to set it to the connector current transaction start date`,
+ );
+ // OCPP specifies that if startSchedule is not defined, it should be relative to start of the connector transaction
+ chargingProfile.chargingSchedule.startSchedule = connectorStatus?.transactionStart;
+ }
+ if (!isDate(chargingProfile.chargingSchedule?.startSchedule)) {
+ logger.warn(
+ `${chargingStation.logPrefix()} ${moduleName}.handleRequestGetCompositeSchedule: Charging profile id ${
+ chargingProfile.chargingProfileId
+ } startSchedule property is not a Date object. Trying to convert it to a Date object`,
+ );
+ chargingProfile.chargingSchedule.startSchedule = convertToDate(
+ chargingProfile.chargingSchedule?.startSchedule,
+ )!;
+ }
+ if (
+ !prepareChargingProfileKind(
+ connectorStatus,
+ chargingProfile,
+ interval.start as Date,
+ chargingStation.logPrefix(),
+ )
+ ) {
+ continue;
+ }
+ if (
+ !canProceedChargingProfile(
+ chargingProfile,
+ interval.start as Date,
+ chargingStation.logPrefix(),
+ )
+ ) {
+ continue;
+ }
+ // Add active charging profiles into chargingProfiles array