- // Deprecation template keys section
- ChargingStationUtils.warnDeprecatedTemplateKey(
- stationTemplate,
- 'supervisionUrl',
- this.templateFile,
- this.logPrefix(),
- "Use 'supervisionUrls' instead"
- );
- ChargingStationUtils.convertDeprecatedTemplateKey(
- stationTemplate,
- 'supervisionUrl',
- 'supervisionUrls'
- );
- const stationInfo: ChargingStationInfo =
- ChargingStationUtils.stationTemplateToStationInfo(stationTemplate);
- stationInfo.hashId = ChargingStationUtils.getHashId(this.index, stationTemplate);
- stationInfo.chargingStationId = ChargingStationUtils.getChargingStationId(
- this.index,
- stationTemplate
- );
- ChargingStationUtils.createSerialNumber(stationTemplate, stationInfo);
- if (!Utils.isEmptyArray(stationTemplate.power)) {
- stationTemplate.power = stationTemplate.power as number[];
- const powerArrayRandomIndex = Math.floor(Utils.secureRandom() * stationTemplate.power.length);
+ }
+
+ // 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)) {
+ stationTemplate.power = stationTemplate.power as number[];
+ const powerArrayRandomIndex = Math.floor(secureRandom() * stationTemplate.power.length);