}
break;
}
+ } else if (chargingProfile.chargingProfileKind === ChargingProfileKindType.RELATIVE) {
+ chargingSchedule.startSchedule =
+ chargingStation.getConnectorStatus(connectorId)?.transactionStart;
}
// Check if the charging profile is active
if (
- isAfter(addSeconds(chargingSchedule.startSchedule, chargingSchedule.duration!), currentDate)
+ isAfter(addSeconds(chargingSchedule.startSchedule!, chargingSchedule.duration!), currentDate)
) {
let lastButOneSchedule: ChargingSchedulePeriod | undefined;
// Search the right schedule period
// Find the right schedule period
if (
isAfter(
- addSeconds(chargingSchedule.startSchedule, schedulePeriod.startPeriod),
+ addSeconds(chargingSchedule.startSchedule!, schedulePeriod.startPeriod),
currentDate,
)
) {
}
if (isNullOrUndefined(commandPayload.connectorId)) {
let clearedCP = false;
- const clearChargingProfiles = (connectorStatus: ConnectorStatus) => {
- if (isNotEmptyArray(connectorStatus?.chargingProfiles)) {
- connectorStatus?.chargingProfiles?.forEach(
- (chargingProfile: OCPP16ChargingProfile, index: number) => {
- let clearCurrentCP = false;
- if (chargingProfile.chargingProfileId === commandPayload.id) {
- clearCurrentCP = true;
- }
- if (
- !commandPayload.chargingProfilePurpose &&
- chargingProfile.stackLevel === commandPayload.stackLevel
- ) {
- clearCurrentCP = true;
- }
- if (
- !chargingProfile.stackLevel &&
- chargingProfile.chargingProfilePurpose === commandPayload.chargingProfilePurpose
- ) {
- clearCurrentCP = true;
- }
- if (
- chargingProfile.stackLevel === commandPayload.stackLevel &&
- chargingProfile.chargingProfilePurpose === commandPayload.chargingProfilePurpose
- ) {
- clearCurrentCP = true;
- }
- if (clearCurrentCP) {
- connectorStatus?.chargingProfiles?.splice(index, 1);
- logger.debug(
- `${chargingStation.logPrefix()} Matching charging profile(s) cleared: %j`,
- chargingProfile,
- );
- clearedCP = true;
- }
- },
- );
- }
- };
if (chargingStation.hasEvses) {
for (const evseStatus of chargingStation.evses.values()) {
for (const connectorStatus of evseStatus.connectors.values()) {
- clearChargingProfiles(connectorStatus);
+ clearedCP = OCPP16ServiceUtils.clearChargingProfiles(
+ chargingStation,
+ commandPayload,
+ connectorStatus.chargingProfiles,
+ );
}
}
} else {
for (const connectorId of chargingStation.connectors.keys()) {
- clearChargingProfiles(chargingStation.getConnectorStatus(connectorId)!);
+ clearedCP = OCPP16ServiceUtils.clearChargingProfiles(
+ chargingStation,
+ commandPayload,
+ chargingStation.getConnectorStatus(connectorId)?.chargingProfiles,
+ );
}
}
if (clearedCP) {
import { type ChargingStation, getIdTagsFile } from '../../../charging-station';
import { OCPPError } from '../../../exception';
import {
+ type ClearChargingProfileRequest,
type ConnectorStatus,
CurrentType,
ErrorType,
!cpReplaced && chargingStation.getConnectorStatus(connectorId)?.chargingProfiles?.push(cp);
}
+ public static clearChargingProfiles = (
+ chargingStation: ChargingStation,
+ commandPayload: ClearChargingProfileRequest,
+ chargingProfiles: OCPP16ChargingProfile[] | undefined,
+ ): boolean => {
+ let clearedCP = false;
+ if (isNotEmptyArray(chargingProfiles)) {
+ chargingProfiles?.forEach((chargingProfile: OCPP16ChargingProfile, index: number) => {
+ let clearCurrentCP = false;
+ if (chargingProfile.chargingProfileId === commandPayload.id) {
+ clearCurrentCP = true;
+ }
+ if (
+ !commandPayload.chargingProfilePurpose &&
+ chargingProfile.stackLevel === commandPayload.stackLevel
+ ) {
+ clearCurrentCP = true;
+ }
+ if (
+ !chargingProfile.stackLevel &&
+ chargingProfile.chargingProfilePurpose === commandPayload.chargingProfilePurpose
+ ) {
+ clearCurrentCP = true;
+ }
+ if (
+ chargingProfile.stackLevel === commandPayload.stackLevel &&
+ chargingProfile.chargingProfilePurpose === commandPayload.chargingProfilePurpose
+ ) {
+ clearCurrentCP = true;
+ }
+ if (clearCurrentCP) {
+ chargingProfiles.splice(index, 1);
+ logger.debug(
+ `${chargingStation.logPrefix()} Matching charging profile(s) cleared: %j`,
+ chargingProfile,
+ );
+ clearedCP = true;
+ }
+ });
+ }
+ return clearedCP;
+ };
+
public static parseJsonSchemaFile<T extends JsonType>(
relativePath: string,
moduleName?: string,