deleteConfigurationKey,
getConfigurationKey,
setConfigurationKeyValue,
-} from './ChargingStationConfigurationKeyUtils';
+} from './ConfigurationKeyUtils';
import {
buildConnectorsMap,
checkConnectorsConfiguration,
propagateSerialNumber,
stationTemplateToStationInfo,
warnTemplateKeysDeprecation,
-} from './ChargingStationUtils';
+} from './Helpers';
import { IdTagsCache } from './IdTagsCache';
import {
OCPP16IncomingRequestService,
RegistrationStatusEnumType,
RequestCommand,
type Reservation,
- ReservationFilterKey,
+ type ReservationFilterKey,
ReservationTerminationReason,
type Response,
StandardParametersKey,
);
}
- public getReservationOnConnectorId0Enabled(): boolean {
+ public getReserveConnectorZeroSupported(): boolean {
return convertToBoolean(
getConfigurationKey(this, StandardParametersKey.ReserveConnectorZeroSupported)!.value,
);
}
public async addReservation(reservation: Reservation): Promise<void> {
- const [exists, reservationFound] = this.doesReservationExists(reservation);
- if (exists) {
+ const reservationFound = this.getReservationBy('reservationId', reservation.reservationId);
+ if (!isUndefined(reservationFound)) {
await this.removeReservation(
reservationFound!,
ReservationTerminationReason.REPLACE_EXISTING,
if (this.hasEvses) {
for (const evseStatus of this.evses.values()) {
for (const connectorStatus of evseStatus.connectors.values()) {
- if (connectorStatus?.reservation?.[filterKey as keyof Reservation] === value) {
+ if (connectorStatus?.reservation?.[filterKey] === value) {
return connectorStatus.reservation;
}
}
}
} else {
for (const connectorStatus of this.connectors.values()) {
- if (connectorStatus?.reservation?.[filterKey as keyof Reservation] === value) {
+ if (connectorStatus?.reservation?.[filterKey] === value) {
return connectorStatus.reservation;
}
}
}
}
- public doesReservationExists(
- reservation: Partial<Reservation>,
- ): [boolean, Reservation | undefined] {
- const foundReservation = this.getReservationBy(
- ReservationFilterKey.RESERVATION_ID,
- reservation.reservationId!,
- );
- return isUndefined(foundReservation) ? [false, undefined] : [true, foundReservation];
- }
-
public startReservationExpirationSetInterval(customInterval?: number): void {
const interval =
customInterval ?? Constants.DEFAULT_RESERVATION_EXPIRATION_OBSERVATION_INTERVAL;
this.startReservationExpirationSetInterval();
}
- public validateIncomingRequestWithReservation(connectorId: number, idTag: string): boolean {
- return this.getReservationBy(ReservationFilterKey.CONNECTOR_ID, connectorId)?.idTag === idTag;
- }
-
public isConnectorReservable(
reservationId: number,
idTag?: string,
connectorId?: number,
): boolean {
- const [alreadyExists] = this.doesReservationExists({ id: reservationId });
- if (alreadyExists) {
- return alreadyExists;
+ const reservationExists = !isUndefined(this.getReservationBy('reservationId', reservationId));
+ if (arguments.length === 1) {
+ return !reservationExists;
+ } else if (arguments.length > 1) {
+ const userReservationExists =
+ !isUndefined(idTag) && isUndefined(this.getReservationBy('idTag', idTag!)) ? false : true;
+ const notConnectorZero = isUndefined(connectorId) ? true : connectorId! > 0;
+ const freeConnectorsAvailable = this.getNumberOfReservableConnectors() > 0;
+ return (
+ !reservationExists && !userReservationExists && notConnectorZero && freeConnectorsAvailable
+ );
}
- const userReservedAlready = isUndefined(
- this.getReservationBy(ReservationFilterKey.ID_TAG, idTag!),
- )
- ? false
- : true;
- const notConnectorZero = isUndefined(connectorId) ? true : connectorId! > 0;
- const freeConnectorsAvailable = this.getNumberOfReservableConnectors() > 0;
- return !alreadyExists && !userReservedAlready && notConnectorZero && freeConnectorsAvailable;
+ return false;
}
private getNumberOfReservableConnectors(): number {