chargingStation: ChargingStation,
connectorId: number,
): number | undefined => {
- let limit: number | undefined, matchingChargingProfile: ChargingProfile | undefined;
+ let limit: number | undefined, chargingProfile: ChargingProfile | undefined;
// Get charging profiles for connector id and sort by stack level
const chargingProfiles = cloneObject<ChargingProfile[]>(
(chargingStation.getConnectorStatus(connectorId)?.chargingProfiles ?? []).concat(
);
if (!isNullOrUndefined(result)) {
limit = result?.limit;
- matchingChargingProfile = result?.matchingChargingProfile;
+ chargingProfile = result?.chargingProfile;
switch (chargingStation.getCurrentOutType()) {
case CurrentType.AC:
limit =
- matchingChargingProfile?.chargingSchedule?.chargingRateUnit ===
- ChargingRateUnitType.WATT
+ chargingProfile?.chargingSchedule?.chargingRateUnit === ChargingRateUnitType.WATT
? limit
: ACElectricUtils.powerTotal(
chargingStation.getNumberOfPhases(),
break;
case CurrentType.DC:
limit =
- matchingChargingProfile?.chargingSchedule?.chargingRateUnit ===
- ChargingRateUnitType.WATT
+ chargingProfile?.chargingSchedule?.chargingRateUnit === ChargingRateUnitType.WATT
? limit
: DCElectricUtils.power(chargingStation.getVoltageOut(), limit!);
}
chargingStation.getMaximumPower() / chargingStation.powerDivider;
if (limit! > connectorMaximumPower) {
logger.error(
- `${chargingStation.logPrefix()} ${moduleName}.getChargingStationConnectorChargingProfilesPowerLimit: Charging profile id ${matchingChargingProfile?.chargingProfileId} limit ${limit} is greater than connector id ${connectorId} maximum ${connectorMaximumPower}: %j`,
+ `${chargingStation.logPrefix()} ${moduleName}.getChargingStationConnectorChargingProfilesPowerLimit: Charging profile id ${chargingProfile?.chargingProfileId} limit ${limit} is greater than connector id ${connectorId} maximum ${connectorMaximumPower}: %j`,
result,
);
limit = connectorMaximumPower;
interface ChargingProfilesLimit {
limit: number;
- matchingChargingProfile: ChargingProfile;
+ chargingProfile: ChargingProfile;
}
/**
if (chargingSchedule.chargingSchedulePeriod.length === 1) {
const result: ChargingProfilesLimit = {
limit: chargingSchedule.chargingSchedulePeriod[0].limit,
- matchingChargingProfile: chargingProfile,
+ chargingProfile,
};
logger.debug(debugLogMsg, result);
return result;
// Found the schedule period: previous is the correct one
const result: ChargingProfilesLimit = {
limit: previousChargingSchedulePeriod!.limit,
- matchingChargingProfile: chargingProfile,
+ chargingProfile: chargingProfile,
};
logger.debug(debugLogMsg, result);
return result;
) {
const result: ChargingProfilesLimit = {
limit: previousChargingSchedulePeriod.limit,
- matchingChargingProfile: chargingProfile,
+ chargingProfile: chargingProfile,
};
logger.debug(debugLogMsg, result);
return result;
import { Client, type FTPResponse } from 'basic-ftp';
import {
addSeconds,
+ isAfter,
+ isBefore,
isDate,
isWithinInterval,
+ max,
maxTime,
min,
+ minTime,
secondsToMilliseconds,
} from 'date-fns';
import { create } from 'tar';
return OCPP16Constants.OCPP_RESPONSE_REJECTED;
}
if (chargingRateUnit) {
- logger.error(
- `${chargingStation.logPrefix()} Get composite schedule with a specified rate unit is not yet supported`,
+ logger.warn(
+ `${chargingStation.logPrefix()} Get composite schedule with a specified rate unit is not yet supported, no conversion will be done`,
);
- return OCPP16Constants.OCPP_RESPONSE_REJECTED;
}
const connectorStatus = chargingStation.getConnectorStatus(connectorId)!;
if (
start: currentDate,
end: addSeconds(currentDate, duration),
};
- const chargingProfiles: OCPP16ChargingProfile[] = [];
- for (const chargingProfile of cloneObject<OCPP16ChargingProfile[]>(
+ const storedChargingProfiles: OCPP16ChargingProfile[] = cloneObject<OCPP16ChargingProfile[]>(
(connectorStatus?.chargingProfiles ?? []).concat(
chargingStation.getConnectorStatus(0)?.chargingProfiles ?? [],
),
- ).sort((a, b) => b.stackLevel - a.stackLevel)) {
+ ).sort((a, b) => b.stackLevel - a.stackLevel);
+ const chargingProfiles: OCPP16ChargingProfile[] = [];
+ for (const storedChargingProfile of storedChargingProfiles) {
if (
connectorStatus?.transactionStarted &&
- isNullOrUndefined(chargingProfile.chargingSchedule?.startSchedule)
+ isNullOrUndefined(storedChargingProfile.chargingSchedule?.startSchedule)
) {
logger.debug(
`${chargingStation.logPrefix()} ${moduleName}.handleRequestGetCompositeSchedule: Charging profile id ${
- chargingProfile.chargingProfileId
+ storedChargingProfile.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;
+ storedChargingProfile.chargingSchedule.startSchedule = connectorStatus?.transactionStart;
}
- if (!isDate(chargingProfile.chargingSchedule?.startSchedule)) {
+ if (!isDate(storedChargingProfile.chargingSchedule?.startSchedule)) {
logger.warn(
`${chargingStation.logPrefix()} ${moduleName}.handleRequestGetCompositeSchedule: Charging profile id ${
- chargingProfile.chargingProfileId
+ storedChargingProfile.chargingProfileId
} startSchedule property is not a Date object. Trying to convert it to a Date object`,
);
- chargingProfile.chargingSchedule.startSchedule = convertToDate(
- chargingProfile.chargingSchedule?.startSchedule,
+ storedChargingProfile.chargingSchedule.startSchedule = convertToDate(
+ storedChargingProfile.chargingSchedule?.startSchedule,
)!;
}
if (
!prepareChargingProfileKind(
connectorStatus,
- chargingProfile,
+ storedChargingProfile,
interval.start as Date,
chargingStation.logPrefix(),
)
}
if (
!canProceedChargingProfile(
- chargingProfile,
+ storedChargingProfile,
interval.start as Date,
chargingStation.logPrefix(),
)
}
// Add active charging profiles into chargingProfiles array
if (
- isValidTime(chargingProfile.chargingSchedule?.startSchedule) &&
- isWithinInterval(chargingProfile.chargingSchedule.startSchedule!, interval)
+ isValidTime(storedChargingProfile.chargingSchedule?.startSchedule) &&
+ isWithinInterval(storedChargingProfile.chargingSchedule.startSchedule!, interval) &&
+ (isEmptyArray(chargingProfiles) ||
+ (isNotEmptyArray(chargingProfiles) &&
+ (isBefore(
+ storedChargingProfile.chargingSchedule.startSchedule!,
+ min(
+ chargingProfiles.map(
+ (chargingProfile) => chargingProfile.chargingSchedule.startSchedule ?? maxTime,
+ ),
+ ),
+ ) ||
+ isAfter(
+ storedChargingProfile.chargingSchedule.startSchedule!,
+ max(
+ chargingProfiles.map(
+ (chargingProfile) =>
+ addSeconds(
+ chargingProfile.chargingSchedule.startSchedule!,
+ chargingProfile.chargingSchedule.duration!,
+ ) ?? minTime,
+ ),
+ ),
+ ))))
) {
- chargingProfiles.push(chargingProfile);
+ chargingProfiles.push(storedChargingProfile);
}
}
const compositeScheduleStart: Date = min(