import type { JSONSchemaType } from 'ajv';
import { OCPP16Constants } from './OCPP16Constants';
-import { type ChargingStation, hasFeatureProfile } from '../../../charging-station';
+import {
+ type ChargingStation,
+ hasFeatureProfile,
+ hasReservationExpired,
+} from '../../../charging-station';
import { OCPPError } from '../../../exception';
import {
type ClearChargingProfileRequest,
}
responses.push(response);
}
- if (
- responses.includes(OCPP16Constants.OCPP_AVAILABILITY_RESPONSE_SCHEDULED) &&
- !responses.includes(OCPP16Constants.OCPP_AVAILABILITY_RESPONSE_REJECTED)
- ) {
+ if (responses.includes(OCPP16Constants.OCPP_AVAILABILITY_RESPONSE_SCHEDULED)) {
return OCPP16Constants.OCPP_AVAILABILITY_RESPONSE_SCHEDULED;
- } else if (responses.includes(OCPP16Constants.OCPP_AVAILABILITY_RESPONSE_REJECTED)) {
- return OCPP16Constants.OCPP_AVAILABILITY_RESPONSE_REJECTED;
}
return OCPP16Constants.OCPP_AVAILABILITY_RESPONSE_ACCEPTED;
};
Array.isArray(chargingStation.getConnectorStatus(connectorId)?.chargingProfiles) === false
) {
logger.error(
- `${chargingStation.logPrefix()} Trying to set a charging profile on connector id ${connectorId} with an improper attribute type for the charging profiles array, applying proper type initialization`,
+ `${chargingStation.logPrefix()} Trying to set a charging profile on connector id ${connectorId} with an improper attribute type for the charging profiles array, applying proper type deferred initialization`,
);
chargingStation.getConnectorStatus(connectorId)!.chargingProfiles = [];
}
commandPayload: ClearChargingProfileRequest,
chargingProfiles: OCPP16ChargingProfile[] | undefined,
): boolean => {
+ const { id, chargingProfilePurpose, stackLevel } = commandPayload;
let clearedCP = false;
if (isNotEmptyArray(chargingProfiles)) {
chargingProfiles?.forEach((chargingProfile: OCPP16ChargingProfile, index: number) => {
let clearCurrentCP = false;
- if (chargingProfile.chargingProfileId === commandPayload.id) {
+ if (chargingProfile.chargingProfileId === id) {
clearCurrentCP = true;
}
- if (
- !commandPayload.chargingProfilePurpose &&
- chargingProfile.stackLevel === commandPayload.stackLevel
- ) {
+ if (!chargingProfilePurpose && chargingProfile.stackLevel === stackLevel) {
clearCurrentCP = true;
}
- if (
- !chargingProfile.stackLevel &&
- chargingProfile.chargingProfilePurpose === commandPayload.chargingProfilePurpose
- ) {
+ if (!stackLevel && chargingProfile.chargingProfilePurpose === chargingProfilePurpose) {
clearCurrentCP = true;
}
if (
- chargingProfile.stackLevel === commandPayload.stackLevel &&
- chargingProfile.chargingProfilePurpose === commandPayload.chargingProfilePurpose
+ chargingProfile.stackLevel === stackLevel &&
+ chargingProfile.chargingProfilePurpose === chargingProfilePurpose
) {
clearCurrentCP = true;
}
return clearedCP;
};
+ public static hasReservation = (
+ chargingStation: ChargingStation,
+ connectorId: number,
+ idTag: string,
+ ): boolean => {
+ const connectorReservation = chargingStation.getReservationBy('connectorId', connectorId);
+ const chargingStationReservation = chargingStation.getReservationBy('connectorId', 0);
+ if (
+ (chargingStation.getConnectorStatus(connectorId)?.status ===
+ OCPP16ChargePointStatus.Reserved &&
+ connectorReservation &&
+ !hasReservationExpired(connectorReservation) &&
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
+ connectorReservation?.idTag === idTag) ||
+ (chargingStation.getConnectorStatus(0)?.status === OCPP16ChargePointStatus.Reserved &&
+ chargingStationReservation &&
+ !hasReservationExpired(chargingStationReservation) &&
+ chargingStationReservation?.idTag === idTag)
+ ) {
+ return true;
+ }
+ return false;
+ };
+
public static parseJsonSchemaFile<T extends JsonType>(
relativePath: string,
moduleName?: string,
}
}
- private static getMeasurandDefaultUnit(
- measurandType: OCPP16MeterValueMeasurand,
- ): MeterValueUnit | undefined {
- switch (measurandType) {
- case OCPP16MeterValueMeasurand.CURRENT_EXPORT:
- case OCPP16MeterValueMeasurand.CURRENT_IMPORT:
- case OCPP16MeterValueMeasurand.CURRENT_OFFERED:
- return MeterValueUnit.AMP;
- case OCPP16MeterValueMeasurand.ENERGY_ACTIVE_EXPORT_REGISTER:
- case OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER:
- return MeterValueUnit.WATT_HOUR;
- case OCPP16MeterValueMeasurand.POWER_ACTIVE_EXPORT:
- case OCPP16MeterValueMeasurand.POWER_ACTIVE_IMPORT:
- case OCPP16MeterValueMeasurand.POWER_OFFERED:
- return MeterValueUnit.WATT;
- case OCPP16MeterValueMeasurand.STATE_OF_CHARGE:
- return MeterValueUnit.PERCENT;
- case OCPP16MeterValueMeasurand.VOLTAGE:
- return MeterValueUnit.VOLT;
- }
- }
+ // private static getMeasurandDefaultUnit(
+ // measurandType: OCPP16MeterValueMeasurand,
+ // ): MeterValueUnit | undefined {
+ // switch (measurandType) {
+ // case OCPP16MeterValueMeasurand.CURRENT_EXPORT:
+ // case OCPP16MeterValueMeasurand.CURRENT_IMPORT:
+ // case OCPP16MeterValueMeasurand.CURRENT_OFFERED:
+ // return MeterValueUnit.AMP;
+ // case OCPP16MeterValueMeasurand.ENERGY_ACTIVE_EXPORT_REGISTER:
+ // case OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER:
+ // return MeterValueUnit.WATT_HOUR;
+ // case OCPP16MeterValueMeasurand.POWER_ACTIVE_EXPORT:
+ // case OCPP16MeterValueMeasurand.POWER_ACTIVE_IMPORT:
+ // case OCPP16MeterValueMeasurand.POWER_OFFERED:
+ // return MeterValueUnit.WATT;
+ // case OCPP16MeterValueMeasurand.STATE_OF_CHARGE:
+ // return MeterValueUnit.PERCENT;
+ // case OCPP16MeterValueMeasurand.VOLTAGE:
+ // return MeterValueUnit.VOLT;
+ // }
+ // }
}