- const startDate = new Date();
- const endDate = new Date(startDate.getTime() + commandPayload.duration * 1000);
- let compositeSchedule: OCPP16ChargingSchedule;
- 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.
+ // Get charging profiles sorted by connector id then stack level
+ const chargingProfiles: OCPP16ChargingProfile[] = getConnectorChargingProfiles(
+ chargingStation,
+ connectorId
+ )
+ let previousCompositeSchedule: OCPP16ChargingSchedule | undefined
+ let compositeSchedule: OCPP16ChargingSchedule | undefined
+ for (const chargingProfile of chargingProfiles) {
+ if (chargingProfile.chargingSchedule.startSchedule == null) {
+ 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 instance. Trying to convert it to a Date instance`
+ )
+ chargingProfile.chargingSchedule.startSchedule = convertToDate(
+ chargingProfile.chargingSchedule.startSchedule
+ )
+ }
+ if (chargingProfile.chargingSchedule.duration == null) {
+ logger.debug(
+ `${chargingStation.logPrefix()} ${moduleName}.handleRequestGetCompositeSchedule: Charging profile id ${
+ chargingProfile.chargingProfileId
+ } has no duration defined and will be set to the maximum time allowed`
+ )
+ // OCPP specifies that if duration is not defined, it should be infinite
+ chargingProfile.chargingSchedule.duration = differenceInSeconds(
+ maxTime,
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ chargingProfile.chargingSchedule.startSchedule!
+ )
+ }
+ if (
+ !prepareChargingProfileKind(
+ connectorStatus,
+ chargingProfile,
+ compositeScheduleInterval.start,
+ chargingStation.logPrefix()
+ )
+ ) {
+ continue
+ }