): ChargingProfilesLimit | undefined => {
const debugLogMsg = `${logPrefix} ${moduleName}.getLimitFromChargingProfiles: Matching charging profile found for power limitation: %j`;
const currentDate = new Date();
- const connectorStatus = chargingStation.getConnectorStatus(connectorId);
+ const connectorStatus = chargingStation.getConnectorStatus(connectorId)!;
if (!isArraySorted(chargingProfiles, (a, b) => b.stackLevel - a.stackLevel)) {
logger.warn(
`${logPrefix} ${moduleName}.getLimitFromChargingProfiles: Charging profiles are not sorted by stack level. Trying to sort them`,
);
chargingSchedule.startSchedule = convertToDate(chargingSchedule?.startSchedule)!;
}
- switch (chargingProfile.chargingProfileKind) {
- case ChargingProfileKindType.RECURRING:
- if (!canProceedRecurringChargingProfile(chargingProfile, logPrefix)) {
- continue;
- }
- prepareRecurringChargingProfile(chargingProfile, currentDate, logPrefix);
- break;
- case ChargingProfileKindType.RELATIVE:
- connectorStatus?.transactionStarted &&
- (chargingSchedule.startSchedule = connectorStatus?.transactionStart);
- break;
+ if (!prepareChargingProfileKind(connectorStatus, chargingProfile, currentDate, logPrefix)) {
+ continue;
}
if (!canProceedChargingProfile(chargingProfile, currentDate, logPrefix)) {
continue;
}
};
+export const prepareChargingProfileKind = (
+ connectorStatus: ConnectorStatus,
+ chargingProfile: ChargingProfile,
+ currentDate: Date,
+ logPrefix: string,
+): boolean => {
+ switch (chargingProfile.chargingProfileKind) {
+ case ChargingProfileKindType.RECURRING:
+ if (!canProceedRecurringChargingProfile(chargingProfile, logPrefix)) {
+ return false;
+ }
+ prepareRecurringChargingProfile(chargingProfile, currentDate, logPrefix);
+ break;
+ case ChargingProfileKindType.RELATIVE:
+ connectorStatus?.transactionStarted &&
+ (chargingProfile.chargingSchedule.startSchedule = connectorStatus?.transactionStart);
+ break;
+ }
+ return true;
+};
+
export const canProceedChargingProfile = (
chargingProfile: ChargingProfile,
currentDate: Date,
return true;
};
-export const canProceedRecurringChargingProfile = (
+const canProceedRecurringChargingProfile = (
chargingProfile: ChargingProfile,
logPrefix: string,
): boolean => {
* @param currentDate -
* @param logPrefix -
*/
-export const prepareRecurringChargingProfile = (
+const prepareRecurringChargingProfile = (
chargingProfile: ChargingProfile,
currentDate: Date,
logPrefix: string,
import {
type ChargingStation,
canProceedChargingProfile,
- canProceedRecurringChargingProfile,
checkChargingStation,
getConfigurationKey,
- prepareRecurringChargingProfile,
+ prepareChargingProfileKind,
removeExpiredReservations,
setConfigurationKeyValue,
} from '../../../charging-station';
import {
type ChangeConfigurationRequest,
type ChangeConfigurationResponse,
- ChargingProfileKindType,
ChargingRateUnitType,
type ClearChargingProfileRequest,
type ClearChargingProfileResponse,
);
return OCPP16Constants.OCPP_RESPONSE_REJECTED;
}
- const connectorStatus = chargingStation.getConnectorStatus(connectorId);
+ const connectorStatus = chargingStation.getConnectorStatus(connectorId)!;
if (
isEmptyArray(
connectorStatus?.chargingProfiles &&
chargingProfile.chargingSchedule?.startSchedule,
)!;
}
- switch (chargingProfile.chargingProfileKind) {
- case ChargingProfileKindType.RECURRING:
- if (!canProceedRecurringChargingProfile(chargingProfile, chargingStation.logPrefix())) {
- continue;
- }
- prepareRecurringChargingProfile(
- chargingProfile,
- interval.start as Date,
- chargingStation.logPrefix(),
- );
- break;
- case ChargingProfileKindType.RELATIVE:
- connectorStatus?.transactionStarted &&
- (chargingProfile.chargingSchedule.startSchedule = connectorStatus?.transactionStart);
- break;
+ if (
+ !prepareChargingProfileKind(
+ connectorStatus,
+ chargingProfile,
+ interval.start as Date,
+ chargingStation.logPrefix(),
+ )
+ ) {
+ continue;
}
if (
!canProceedChargingProfile(