+ public supportsReservations(): boolean {
+ logger.info(`${this.logPrefix()} Check for reservation support in charging station`);
+ return ChargingStationConfigurationUtils.getConfigurationKey(
+ this,
+ StandardParametersKey.SupportedFeatureProfiles
+ ).value.includes(OCPP16SupportedFeatureProfiles.Reservation);
+ }
+
+ public supportsReservationsOnConnectorId0(): boolean {
+ logger.info(
+ `Check for reservation support on connector 0 in charging station (CS): ${this.logPrefix()}`
+ );
+ return (
+ this.supportsReservations() &&
+ ChargingStationConfigurationUtils.getConfigurationKey(
+ this,
+ OCPPConstants.OCPP_RESERVE_CONNECTOR_ZERO_SUPPORTED
+ ).value === 'true'
+ );
+ }
+
+ public addReservation(newReservation: Reservation): void {
+ if (Utils.isNullOrUndefined(this.reservations)) {
+ this.reservations = [];
+ }
+ const [exists, foundReservation] = this.doesReservationExist(newReservation.reservationId);
+ if (exists) {
+ this.replaceExistingReservation(foundReservation, newReservation);
+ } else {
+ this.reservations.push(newReservation);
+ }
+ }
+
+ public removeReservation(existingReservationId: number): void {
+ const index = this.reservations.findIndex((res) => res.reservationId === existingReservationId);
+ this.reservations.splice(index, 1);
+ }
+
+ public getReservation(reservationId: number, reservationIndex?: number): Reservation {
+ if (!Utils.isNullOrUndefined(reservationIndex)) {
+ return this.reservations[reservationIndex];
+ }
+ return this.reservations.find((r) => r.reservationId === reservationId);
+ }
+
+ public doesReservationExist(
+ reservationId: number,
+ reservation?: Reservation
+ ): [boolean, Reservation] {
+ const foundReservation = this.reservations.find(
+ (r) => r.reservationId === reservationId || r.reservationId === reservation.reservationId
+ );
+ return Utils.isUndefined(foundReservation) ? [false, null] : [true, foundReservation];
+ }
+
+ public getReservationByConnectorId(connectorId: number): Reservation {
+ return this.reservations.find((r) => r.connectorId === connectorId);
+ }
+
+ public getAvailableConnector(): Map<number, ConnectorStatus> {
+ for (const connectorId in this.connectors) {
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
+ const connector = this.connectors[Utils.convertToInt(connectorId)];
+ if (
+ this.isConnectorAvailable(Utils.convertToInt(connectorId)) &&
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
+ connector.status === OCPP20ConnectorStatusEnumType.Available
+ ) {
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
+ return connector;
+ }
+ }
+ }
+