+ return false;
+ }
+
+ private startReservationExpirationSetInterval(customInterval?: number): void {
+ const interval = customInterval ?? Constants.DEFAULT_RESERVATION_EXPIRATION_INTERVAL;
+ if (interval > 0) {
+ logger.info(
+ `${this.logPrefix()} Reservation expiration date checks started every ${formatDurationMilliSeconds(
+ interval,
+ )}`,
+ );
+ this.reservationExpirationSetInterval = setInterval((): void => {
+ removeExpiredReservations(this).catch(Constants.EMPTY_FUNCTION);
+ }, interval);
+ }
+ }
+
+ private stopReservationExpirationSetInterval(): void {
+ if (!isNullOrUndefined(this.reservationExpirationSetInterval)) {
+ clearInterval(this.reservationExpirationSetInterval);
+ }
+ }
+
+ // private restartReservationExpiryDateSetInterval(): void {
+ // this.stopReservationExpirationSetInterval();
+ // this.startReservationExpirationSetInterval();
+ // }
+
+ private getNumberOfReservableConnectors(): number {
+ let numberOfReservableConnectors = 0;
+ if (this.hasEvses) {
+ for (const evseStatus of this.evses.values()) {
+ numberOfReservableConnectors += getNumberOfReservableConnectors(evseStatus.connectors);
+ }
+ } else {
+ numberOfReservableConnectors = getNumberOfReservableConnectors(this.connectors);
+ }
+ return numberOfReservableConnectors - this.getNumberOfReservationsOnConnectorZero();
+ }
+
+ private getNumberOfReservationsOnConnectorZero(): number {
+ if (
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
+ (this.hasEvses && this.evses.get(0)?.connectors.get(0)?.reservation) ||
+ (!this.hasEvses && this.connectors.get(0)?.reservation)
+ ) {
+ return 1;
+ }
+ return 0;
+ }
+
+ private flushMessageBuffer(): void {
+ if (this.messageBuffer.size > 0) {
+ for (const message of this.messageBuffer.values()) {
+ let beginId: string | undefined;
+ let commandName: RequestCommand | undefined;
+ const [messageType] = JSON.parse(message) as OutgoingRequest | Response | ErrorResponse;
+ const isRequest = messageType === MessageType.CALL_MESSAGE;
+ if (isRequest) {
+ [, , commandName] = JSON.parse(message) as OutgoingRequest;
+ beginId = PerformanceStatistics.beginMeasure(commandName);
+ }
+ this.wsConnection?.send(message);
+ isRequest && PerformanceStatistics.endMeasure(commandName!, beginId!);
+ logger.debug(
+ `${this.logPrefix()} >> Buffered ${OCPPServiceUtils.getMessageTypeString(
+ messageType,
+ )} payload sent: ${message}`,
+ );
+ this.messageBuffer.delete(message);
+ }
+ }
+ }
+
+ private getTemplateFromFile(): ChargingStationTemplate | undefined {
+ let template: ChargingStationTemplate | undefined;
+ try {
+ if (this.sharedLRUCache.hasChargingStationTemplate(this.templateFileHash)) {
+ template = this.sharedLRUCache.getChargingStationTemplate(this.templateFileHash);
+ } else {
+ const measureId = `${FileType.ChargingStationTemplate} read`;
+ const beginId = PerformanceStatistics.beginMeasure(measureId);
+ template = JSON.parse(readFileSync(this.templateFile, 'utf8')) as ChargingStationTemplate;
+ PerformanceStatistics.endMeasure(measureId, beginId);
+ template.templateHash = createHash(Constants.DEFAULT_HASH_ALGORITHM)
+ .update(JSON.stringify(template))
+ .digest('hex');
+ this.sharedLRUCache.setChargingStationTemplate(template);
+ this.templateFileHash = template.templateHash;
+ }
+ } catch (error) {
+ handleFileException(
+ this.templateFile,
+ FileType.ChargingStationTemplate,
+ error as NodeJS.ErrnoException,
+ this.logPrefix(),
+ );
+ }
+ return template;
+ }
+
+ private getStationInfoFromTemplate(): ChargingStationInfo {
+ const stationTemplate: ChargingStationTemplate = this.getTemplateFromFile()!;
+ checkTemplate(stationTemplate, this.logPrefix(), this.templateFile);
+ const warnTemplateKeysDeprecationOnce = once(warnTemplateKeysDeprecation, this);
+ warnTemplateKeysDeprecationOnce(stationTemplate, this.logPrefix(), this.templateFile);
+ if (stationTemplate?.Connectors) {
+ checkConnectorsConfiguration(stationTemplate, this.logPrefix(), this.templateFile);
+ }
+ const stationInfo: ChargingStationInfo = stationTemplateToStationInfo(stationTemplate);
+ stationInfo.hashId = getHashId(this.index, stationTemplate);
+ stationInfo.chargingStationId = getChargingStationId(this.index, stationTemplate);
+ stationInfo.ocppVersion = stationTemplate?.ocppVersion ?? OCPPVersion.VERSION_16;
+ createSerialNumber(stationTemplate, stationInfo);
+ stationInfo.voltageOut = this.getVoltageOut(stationInfo);
+ if (isNotEmptyArray(stationTemplate?.power)) {