refactor: remove getter on stationInfo properties
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 10 Nov 2023 20:17:40 +0000 (21:17 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 10 Nov 2023 20:17:40 +0000 (21:17 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/Helpers.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
src/charging-station/ocpp/1.6/OCPP16RequestService.ts
src/charging-station/ocpp/1.6/OCPP16ResponseService.ts
src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts
src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts
src/charging-station/ocpp/OCPPIncomingRequestService.ts
src/charging-station/ocpp/OCPPRequestService.ts
src/charging-station/ocpp/OCPPResponseService.ts
src/charging-station/ocpp/OCPPServiceUtils.ts

index 033152d6bf0d62c760f4477f3324351198c4f31b..ae5f0fd1a965a6ea8b58660adce1dbf5873ec440 100644 (file)
@@ -157,7 +157,6 @@ import {
 export class ChargingStation extends EventEmitter {
   public readonly index: number;
   public readonly templateFile: string;
-  public stationInfo!: ChargingStationInfo;
   public started: boolean;
   public starting: boolean;
   public idTagsCache: IdTagsCache;
@@ -173,6 +172,7 @@ export class ChargingStation extends EventEmitter {
   public bootNotificationRequest!: BootNotificationRequest;
   public bootNotificationResponse!: BootNotificationResponse | undefined;
   public powerDivider!: number;
+  private internalStationInfo!: ChargingStationInfo;
   private stopping: boolean;
   private configurationFile!: string;
   private configurationFileHash!: string;
@@ -226,13 +226,42 @@ export class ChargingStation extends EventEmitter {
     return this.connectors.size === 0 && this.evses.size > 0;
   }
 
+  public get stationInfo(): ChargingStationInfo {
+    return {
+      ...this.internalStationInfo,
+      ...{
+        enableStatistics: false,
+        remoteAuthorization: true,
+        currentOutType: CurrentType.AC,
+        ocppStrictCompliance: true,
+        outOfOrderEndMeterValues: false,
+        beginEndMeterValues: false,
+        meteringPerTransaction: true,
+        transactionDataMeterValues: false,
+        mainVoltageMeterValues: true,
+        phaseLineToLineVoltageMeterValues: false,
+        customValueLimitationMeterValues: true,
+        supervisionUrlOcppConfiguration: false,
+        supervisionUrlOcppKey: VendorParametersKey.ConnectionUrl,
+        ocppVersion: OCPPVersion.VERSION_16,
+        ocppPersistentConfiguration: true,
+        stationInfoPersistentConfiguration: true,
+        automaticTransactionGeneratorPersistentConfiguration: true,
+        autoReconnectMaxRetries: -1,
+        registrationMaxRetries: -1,
+        reconnectExponentialDelay: false,
+        stopTransactionsOnStopped: true,
+      },
+    };
+  }
+
   private get wsConnectionUrl(): URL {
     return new URL(
       `${
-        this.getSupervisionUrlOcppConfiguration() &&
-        isNotEmptyString(this.getSupervisionUrlOcppKey()) &&
-        isNotEmptyString(getConfigurationKey(this, this.getSupervisionUrlOcppKey())?.value)
-          ? getConfigurationKey(this, this.getSupervisionUrlOcppKey())!.value
+        this.stationInfo?.supervisionUrlOcppConfiguration &&
+        isNotEmptyString(this.stationInfo?.supervisionUrlOcppKey) &&
+        isNotEmptyString(getConfigurationKey(this, this.stationInfo.supervisionUrlOcppKey!)?.value)
+          ? getConfigurationKey(this, this.stationInfo.supervisionUrlOcppKey!)!.value
           : this.configuredSupervisionUrl.href
       }/${this.stationInfo.chargingStationId}`,
     );
@@ -253,14 +282,6 @@ export class ChargingStation extends EventEmitter {
     return isNotEmptyArray(this.idTagsCache.getIdTags(getIdTagsFile(this.stationInfo)!));
   }
 
-  public getEnableStatistics(): boolean {
-    return this.stationInfo.enableStatistics ?? false;
-  }
-
-  public getRemoteAuthorization(): boolean {
-    return this.stationInfo.remoteAuthorization ?? true;
-  }
-
   public getNumberOfPhases(stationInfo?: ChargingStationInfo): number {
     const localStationInfo: ChargingStationInfo = stationInfo ?? this.stationInfo;
     switch (this.getCurrentOutType(stationInfo)) {
@@ -354,27 +375,6 @@ export class ChargingStation extends EventEmitter {
     return this.connectors.get(connectorId);
   }
 
-  public getCurrentOutType(stationInfo?: ChargingStationInfo): CurrentType {
-    return (stationInfo ?? this.stationInfo)?.currentOutType ?? CurrentType.AC;
-  }
-
-  public getOcppStrictCompliance(): boolean {
-    return this.stationInfo?.ocppStrictCompliance ?? true;
-  }
-
-  public getVoltageOut(stationInfo?: ChargingStationInfo): number {
-    const defaultVoltageOut = getDefaultVoltageOut(
-      this.getCurrentOutType(stationInfo),
-      this.logPrefix(),
-      this.templateFile,
-    );
-    return (stationInfo ?? this.stationInfo).voltageOut ?? defaultVoltageOut;
-  }
-
-  public getMaximumPower(stationInfo?: ChargingStationInfo): number {
-    return (stationInfo ?? this.stationInfo).maximumPower!;
-  }
-
   public getConnectorMaximumAvailablePower(connectorId: number): number {
     let connectorAmperageLimitationPowerLimit: number | undefined;
     if (
@@ -382,17 +382,17 @@ export class ChargingStation extends EventEmitter {
       this.getAmperageLimitation()! < this.stationInfo.maximumAmperage!
     ) {
       connectorAmperageLimitationPowerLimit =
-        (this.getCurrentOutType() === CurrentType.AC
+        (this.stationInfo?.currentOutType === CurrentType.AC
           ? ACElectricUtils.powerTotal(
               this.getNumberOfPhases(),
-              this.getVoltageOut(),
+              this.stationInfo.voltageOut!,
               this.getAmperageLimitation()! *
                 (this.hasEvses ? this.getNumberOfEvses() : this.getNumberOfConnectors()),
             )
-          : DCElectricUtils.power(this.getVoltageOut(), this.getAmperageLimitation()!)) /
+          : DCElectricUtils.power(this.stationInfo.voltageOut!, this.getAmperageLimitation()!)) /
         this.powerDivider;
     }
-    const connectorMaximumPower = this.getMaximumPower() / this.powerDivider;
+    const connectorMaximumPower = this.stationInfo.maximumPower! / this.powerDivider;
     const connectorChargingProfilesPowerLimit =
       getChargingStationConnectorChargingProfilesPowerLimit(this, connectorId);
     return min(
@@ -445,34 +445,6 @@ export class ChargingStation extends EventEmitter {
     return numberOfRunningTransactions;
   }
 
-  public getOutOfOrderEndMeterValues(): boolean {
-    return this.stationInfo?.outOfOrderEndMeterValues ?? false;
-  }
-
-  public getBeginEndMeterValues(): boolean {
-    return this.stationInfo?.beginEndMeterValues ?? false;
-  }
-
-  public getMeteringPerTransaction(): boolean {
-    return this.stationInfo?.meteringPerTransaction ?? true;
-  }
-
-  public getTransactionDataMeterValues(): boolean {
-    return this.stationInfo?.transactionDataMeterValues ?? false;
-  }
-
-  public getMainVoltageMeterValues(): boolean {
-    return this.stationInfo?.mainVoltageMeterValues ?? true;
-  }
-
-  public getPhaseLineToLineVoltageMeterValues(): boolean {
-    return this.stationInfo?.phaseLineToLineVoltageMeterValues ?? false;
-  }
-
-  public getCustomValueLimitationMeterValues(): boolean {
-    return this.stationInfo?.customValueLimitationMeterValues ?? true;
-  }
-
   public getConnectorIdByTransactionId(transactionId: number): number | undefined {
     if (this.hasEvses) {
       for (const evseStatus of this.evses.values()) {
@@ -541,10 +513,10 @@ export class ChargingStation extends EventEmitter {
 
   public setSupervisionUrl(url: string): void {
     if (
-      this.getSupervisionUrlOcppConfiguration() &&
-      isNotEmptyString(this.getSupervisionUrlOcppKey())
+      this.stationInfo?.supervisionUrlOcppConfiguration &&
+      isNotEmptyString(this.stationInfo?.supervisionUrlOcppKey)
     ) {
-      setConfigurationKeyValue(this, this.getSupervisionUrlOcppKey(), url);
+      setConfigurationKeyValue(this, this.stationInfo.supervisionUrlOcppKey!, url);
     } else {
       this.stationInfo.supervisionUrls = url;
       this.saveStationInfo();
@@ -669,7 +641,7 @@ export class ChargingStation extends EventEmitter {
     if (this.started === false) {
       if (this.starting === false) {
         this.starting = true;
-        if (this.getEnableStatistics() === true) {
+        if (this.stationInfo?.enableStatistics === true) {
           this.performanceStatistics?.start();
         }
         if (hasFeatureProfile(this, SupportedFeatureProfiles.Reservation)) {
@@ -700,7 +672,7 @@ export class ChargingStation extends EventEmitter {
                 if (this.getAutomaticTransactionGeneratorConfiguration().enable === true) {
                   this.startAutomaticTransactionGenerator();
                 }
-                if (this.getEnableStatistics() === true) {
+                if (this.stationInfo?.enableStatistics === true) {
                   this.performanceStatistics?.restart();
                 } else {
                   this.performanceStatistics?.stop();
@@ -732,7 +704,7 @@ export class ChargingStation extends EventEmitter {
         this.stopping = true;
         await this.stopMessageSequence(reason, stopTransactions);
         this.closeWSConnection();
-        if (this.getEnableStatistics() === true) {
+        if (this.stationInfo?.enableStatistics === true) {
           this.performanceStatistics?.stop();
         }
         if (hasFeatureProfile(this, SupportedFeatureProfiles.Reservation)) {
@@ -762,7 +734,7 @@ export class ChargingStation extends EventEmitter {
   }
 
   public saveOcppConfiguration(): void {
-    if (this.getOcppPersistentConfiguration()) {
+    if (this.stationInfo?.ocppPersistentConfiguration === true) {
       this.saveConfiguration();
     }
   }
@@ -810,7 +782,7 @@ export class ChargingStation extends EventEmitter {
 
     this.wsConnection = new WebSocket(
       this.wsConnectionUrl,
-      `ocpp${this.stationInfo.ocppVersion ?? OCPPVersion.VERSION_16}`,
+      `ocpp${this.stationInfo.ocppVersion}`,
       options,
     );
 
@@ -852,7 +824,7 @@ export class ChargingStation extends EventEmitter {
       const stationTemplate = this.getTemplateFromFile();
       const stationConfiguration = this.getConfigurationFromFile();
       if (
-        this.getAutomaticTransactionGeneratorPersistentConfiguration() &&
+        this.stationInfo?.automaticTransactionGeneratorPersistentConfiguration === true &&
         stationConfiguration?.stationInfo?.templateHash === stationTemplate?.templateHash &&
         stationConfiguration?.automaticTransactionGenerator
       ) {
@@ -904,9 +876,9 @@ export class ChargingStation extends EventEmitter {
   ): Promise<StopTransactionResponse> {
     const transactionId = this.getConnectorStatus(connectorId)?.transactionId;
     if (
-      this.getBeginEndMeterValues() === true &&
-      this.getOcppStrictCompliance() === true &&
-      this.getOutOfOrderEndMeterValues() === false
+      this.stationInfo?.beginEndMeterValues === true &&
+      this.stationInfo?.ocppStrictCompliance === true &&
+      this.stationInfo?.outOfOrderEndMeterValues === false
     ) {
       // FIXME: Implement OCPP version agnostic helpers
       const transactionEndMeterValue = OCPP16ServiceUtils.buildTransactionEndMeterValue(
@@ -1103,14 +1075,6 @@ export class ChargingStation extends EventEmitter {
     }
   }
 
-  private getSupervisionUrlOcppConfiguration(): boolean {
-    return this.stationInfo.supervisionUrlOcppConfiguration ?? false;
-  }
-
-  private getSupervisionUrlOcppKey(): string {
-    return this.stationInfo.supervisionUrlOcppKey ?? VendorParametersKey.ConnectionUrl;
-  }
-
   private getTemplateFromFile(): ChargingStationTemplate | undefined {
     let template: ChargingStationTemplate | undefined;
     try {
@@ -1195,7 +1159,7 @@ export class ChargingStation extends EventEmitter {
 
   private getStationInfoFromFile(): ChargingStationInfo | undefined {
     let stationInfo: ChargingStationInfo | undefined;
-    if (this.getStationInfoPersistentConfiguration()) {
+    if (this.stationInfo?.stationInfoPersistentConfiguration === true) {
       stationInfo = this.getConfigurationFromFile()?.stationInfo;
       if (stationInfo) {
         delete stationInfo?.infoHash;
@@ -1223,23 +1187,11 @@ export class ChargingStation extends EventEmitter {
   }
 
   private saveStationInfo(): void {
-    if (this.getStationInfoPersistentConfiguration()) {
+    if (this.stationInfo?.stationInfoPersistentConfiguration === true) {
       this.saveConfiguration();
     }
   }
 
-  private getOcppPersistentConfiguration(): boolean {
-    return this.stationInfo?.ocppPersistentConfiguration ?? true;
-  }
-
-  private getStationInfoPersistentConfiguration(): boolean {
-    return this.stationInfo?.stationInfoPersistentConfiguration ?? true;
-  }
-
-  private getAutomaticTransactionGeneratorPersistentConfiguration(): boolean {
-    return this.stationInfo?.automaticTransactionGeneratorPersistentConfiguration ?? true;
-  }
-
   private handleUnsupportedVersion(version: OCPPVersion) {
     const errorMsg = `Unsupported protocol version '${version}' configured in template file ${this.templateFile}`;
     logger.error(`${this.logPrefix()} ${errorMsg}`);
@@ -1263,7 +1215,7 @@ export class ChargingStation extends EventEmitter {
     } else {
       this.initializeConnectorsOrEvsesFromTemplate(stationTemplate);
     }
-    this.stationInfo = this.getStationInfo();
+    this.internalStationInfo = this.getStationInfo();
     if (
       this.stationInfo.firmwareStatus === FirmwareStatus.Installing &&
       isNotEmptyString(this.stationInfo.firmwareVersion) &&
@@ -1284,7 +1236,7 @@ export class ChargingStation extends EventEmitter {
     }
     this.saveStationInfo();
     this.configuredSupervisionUrl = this.getConfiguredSupervisionUrl();
-    if (this.getEnableStatistics() === true) {
+    if (this.stationInfo?.enableStatistics === true) {
       this.performanceStatistics = PerformanceStatistics.getInstance(
         this.stationInfo.hashId,
         this.stationInfo.chargingStationId!,
@@ -1307,7 +1259,7 @@ export class ChargingStation extends EventEmitter {
   }
 
   private initializeOcppServices(): void {
-    const ocppVersion = this.stationInfo.ocppVersion ?? OCPPVersion.VERSION_16;
+    const ocppVersion = this.stationInfo.ocppVersion;
     switch (ocppVersion) {
       case OCPPVersion.VERSION_16:
         this.ocppIncomingRequestService =
@@ -1338,22 +1290,22 @@ export class ChargingStation extends EventEmitter {
       addConfigurationKey(this, StandardParametersKey.HeartBeatInterval, '0', { visible: false });
     }
     if (
-      this.getSupervisionUrlOcppConfiguration() &&
-      isNotEmptyString(this.getSupervisionUrlOcppKey()) &&
-      !getConfigurationKey(this, this.getSupervisionUrlOcppKey())
+      this.stationInfo?.supervisionUrlOcppConfiguration &&
+      isNotEmptyString(this.stationInfo?.supervisionUrlOcppKey) &&
+      !getConfigurationKey(this, this.stationInfo.supervisionUrlOcppKey!)
     ) {
       addConfigurationKey(
         this,
-        this.getSupervisionUrlOcppKey(),
+        this.stationInfo.supervisionUrlOcppKey!,
         this.configuredSupervisionUrl.href,
         { reboot: true },
       );
     } else if (
-      !this.getSupervisionUrlOcppConfiguration() &&
-      isNotEmptyString(this.getSupervisionUrlOcppKey()) &&
-      getConfigurationKey(this, this.getSupervisionUrlOcppKey())
+      !this.stationInfo?.supervisionUrlOcppConfiguration &&
+      isNotEmptyString(this.stationInfo?.supervisionUrlOcppKey) &&
+      getConfigurationKey(this, this.stationInfo.supervisionUrlOcppKey!)
     ) {
-      deleteConfigurationKey(this, this.getSupervisionUrlOcppKey(), { save: false });
+      deleteConfigurationKey(this, this.stationInfo.supervisionUrlOcppKey!, { save: false });
     }
     if (
       isNotEmptyString(this.stationInfo?.amperageLimitationOcppKey) &&
@@ -1644,7 +1596,7 @@ export class ChargingStation extends EventEmitter {
   }
 
   private saveAutomaticTransactionGeneratorConfiguration(): void {
-    if (this.getAutomaticTransactionGeneratorPersistentConfiguration()) {
+    if (this.stationInfo?.automaticTransactionGeneratorPersistentConfiguration === true) {
       this.saveConfiguration();
     }
   }
@@ -1666,12 +1618,15 @@ export class ChargingStation extends EventEmitter {
         let configurationData: ChargingStationConfiguration = this.getConfigurationFromFile()
           ? cloneObject<ChargingStationConfiguration>(this.getConfigurationFromFile()!)
           : {};
-        if (this.getStationInfoPersistentConfiguration() && this.stationInfo) {
+        if (this.stationInfo?.stationInfoPersistentConfiguration === true && this.stationInfo) {
           configurationData.stationInfo = this.stationInfo;
         } else {
           delete configurationData.stationInfo;
         }
-        if (this.getOcppPersistentConfiguration() && this.ocppConfiguration?.configurationKey) {
+        if (
+          this.stationInfo?.ocppPersistentConfiguration === true &&
+          this.ocppConfiguration?.configurationKey
+        ) {
           configurationData.configurationKey = this.ocppConfiguration.configurationKey;
         } else {
           delete configurationData.configurationKey;
@@ -1681,7 +1636,7 @@ export class ChargingStation extends EventEmitter {
           buildChargingStationAutomaticTransactionGeneratorConfiguration(this),
         );
         if (
-          !this.getAutomaticTransactionGeneratorPersistentConfiguration() ||
+          !this.stationInfo?.automaticTransactionGeneratorPersistentConfiguration ||
           !this.getAutomaticTransactionGeneratorConfiguration()
         ) {
           delete configurationData.automaticTransactionGenerator;
@@ -1760,7 +1715,7 @@ export class ChargingStation extends EventEmitter {
 
   private getOcppConfigurationFromFile(): ChargingStationOcppConfiguration | undefined {
     const configurationKey = this.getConfigurationFromFile()?.configurationKey;
-    if (this.getOcppPersistentConfiguration() === true && configurationKey) {
+    if (this.stationInfo?.ocppPersistentConfiguration === true && configurationKey) {
       return { configurationKey };
     }
     return undefined;
@@ -1791,7 +1746,7 @@ export class ChargingStation extends EventEmitter {
             skipBufferingOnError: true,
           });
           if (this.isRegistered() === false) {
-            this.getRegistrationMaxRetries() !== -1 && ++registrationRetryCount;
+            this.stationInfo?.registrationMaxRetries !== -1 && ++registrationRetryCount;
             await sleep(
               this?.bootNotificationResponse?.interval
                 ? secondsToMilliseconds(this.bootNotificationResponse.interval)
@@ -1800,8 +1755,8 @@ export class ChargingStation extends EventEmitter {
           }
         } while (
           this.isRegistered() === false &&
-          (registrationRetryCount <= this.getRegistrationMaxRetries()! ||
-            this.getRegistrationMaxRetries() === -1)
+          (registrationRetryCount <= this.stationInfo.registrationMaxRetries! ||
+            this.stationInfo?.registrationMaxRetries) === -1
         );
       }
       if (this.isRegistered() === true) {
@@ -1812,7 +1767,8 @@ export class ChargingStation extends EventEmitter {
         }
       } else {
         logger.error(
-          `${this.logPrefix()} Registration failure: max retries reached (${this.getRegistrationMaxRetries()}) or retry disabled (${this.getRegistrationMaxRetries()})`,
+          `${this.logPrefix()} Registration failure: max retries reached or retry disabled (${this
+            .stationInfo?.registrationMaxRetries})`,
         );
       }
       this.wsConnectionRestarted = false;
@@ -1867,7 +1823,7 @@ export class ChargingStation extends EventEmitter {
 
   private async handleIncomingMessage(request: IncomingRequest): Promise<void> {
     const [messageType, messageId, commandName, commandPayload] = request;
-    if (this.getEnableStatistics() === true) {
+    if (this.stationInfo.enableStatistics === true) {
       this.performanceStatistics?.addRequestStatistic(commandName, messageType);
     }
     logger.debug(
@@ -2029,7 +1985,7 @@ export class ChargingStation extends EventEmitter {
   }
 
   private getEnergyActiveImportRegister(connectorStatus: ConnectorStatus, rounded = false): number {
-    if (this.getMeteringPerTransaction() === true) {
+    if (this.stationInfo?.meteringPerTransaction === true) {
       return (
         (rounded === true
           ? Math.round(connectorStatus.transactionEnergyActiveImportRegisterValue!)
@@ -2079,16 +2035,6 @@ export class ChargingStation extends EventEmitter {
     return Constants.DEFAULT_CONNECTION_TIMEOUT;
   }
 
-  // -1 for unlimited, 0 for disabling
-  private getAutoReconnectMaxRetries(): number | undefined {
-    return this.stationInfo.autoReconnectMaxRetries ?? -1;
-  }
-
-  // -1 for unlimited, 0 for disabling
-  private getRegistrationMaxRetries(): number | undefined {
-    return this.stationInfo.registrationMaxRetries ?? -1;
-  }
-
   private getPowerDivider(): number {
     let powerDivider = this.hasEvses ? this.getNumberOfEvses() : this.getNumberOfConnectors();
     if (this.stationInfo?.powerSharedByConnectors) {
@@ -2111,6 +2057,23 @@ export class ChargingStation extends EventEmitter {
     }
   }
 
+  private getMaximumPower(stationInfo?: ChargingStationInfo): number {
+    return (stationInfo ?? this.stationInfo).maximumPower!;
+  }
+
+  private getCurrentOutType(stationInfo?: ChargingStationInfo): CurrentType {
+    return (stationInfo ?? this.stationInfo).currentOutType!;
+  }
+
+  private getVoltageOut(stationInfo?: ChargingStationInfo): number {
+    const defaultVoltageOut = getDefaultVoltageOut(
+      this.getCurrentOutType(stationInfo),
+      this.logPrefix(),
+      this.templateFile,
+    );
+    return (stationInfo ?? this.stationInfo).voltageOut ?? defaultVoltageOut;
+  }
+
   private getAmperageLimitation(): number | undefined {
     if (
       isNotEmptyString(this.stationInfo?.amperageLimitationOcppKey) &&
@@ -2183,7 +2146,7 @@ export class ChargingStation extends EventEmitter {
 
   private async stopMessageSequence(
     reason?: StopTransactionReason,
-    stopTransactions = this.stationInfo?.stopTransactionsOnStopped ?? true,
+    stopTransactions = this.stationInfo?.stopTransactionsOnStopped,
   ): Promise<void> {
     // Stop WebSocket ping
     this.stopWebSocketPing();
@@ -2327,10 +2290,6 @@ export class ChargingStation extends EventEmitter {
     }
   }
 
-  private getReconnectExponentialDelay(): boolean {
-    return this.stationInfo?.reconnectExponentialDelay ?? false;
-  }
-
   private async reconnect(): Promise<void> {
     // Stop WebSocket ping
     this.stopWebSocketPing();
@@ -2341,13 +2300,14 @@ export class ChargingStation extends EventEmitter {
       this.stopAutomaticTransactionGenerator();
     }
     if (
-      this.autoReconnectRetryCount < this.getAutoReconnectMaxRetries()! ||
-      this.getAutoReconnectMaxRetries() === -1
+      this.autoReconnectRetryCount < this.stationInfo.autoReconnectMaxRetries! ||
+      this.stationInfo?.autoReconnectMaxRetries === -1
     ) {
       ++this.autoReconnectRetryCount;
-      const reconnectDelay = this.getReconnectExponentialDelay()
-        ? exponentialDelay(this.autoReconnectRetryCount)
-        : secondsToMilliseconds(this.getConnectionTimeout());
+      const reconnectDelay =
+        this.stationInfo?.reconnectExponentialDelay === true
+          ? exponentialDelay(this.autoReconnectRetryCount)
+          : secondsToMilliseconds(this.getConnectionTimeout());
       const reconnectDelayWithdraw = 1000;
       const reconnectTimeout =
         reconnectDelay && reconnectDelay - reconnectDelayWithdraw > 0
@@ -2370,11 +2330,11 @@ export class ChargingStation extends EventEmitter {
         { closeOpened: true },
       );
       this.wsConnectionRestarted = true;
-    } else if (this.getAutoReconnectMaxRetries() !== -1) {
+    } else if (this.stationInfo?.autoReconnectMaxRetries !== -1) {
       logger.error(
         `${this.logPrefix()} WebSocket connection retries failure: maximum retries reached (${
           this.autoReconnectRetryCount
-        }) or retries disabled (${this.getAutoReconnectMaxRetries()})`,
+        }) or retries disabled (${this.stationInfo?.autoReconnectMaxRetries})`,
       );
     }
   }
index 99a8f82cb5dca431de4f3c6f49ca044129f16c7e..e66043e9906cd1d00e185a733ad5c2fdb67f0cc6 100644 (file)
@@ -363,7 +363,7 @@ export const createBootNotificationRequest = (
   stationInfo: ChargingStationInfo,
   bootReason: BootReasonEnumType = BootReasonEnumType.PowerUp,
 ): BootNotificationRequest => {
-  const ocppVersion = stationInfo.ocppVersion ?? OCPPVersion.VERSION_16;
+  const ocppVersion = stationInfo.ocppVersion!;
   switch (ocppVersion) {
     case OCPPVersion.VERSION_16:
       return {
@@ -559,14 +559,14 @@ export const getChargingStationConnectorChargingProfilesPowerLimit = (
     if (!isNullOrUndefined(result)) {
       limit = result?.limit;
       chargingProfile = result?.chargingProfile;
-      switch (chargingStation.getCurrentOutType()) {
+      switch (chargingStation.stationInfo?.currentOutType) {
         case CurrentType.AC:
           limit =
             chargingProfile?.chargingSchedule?.chargingRateUnit === ChargingRateUnitType.WATT
               ? limit
               : ACElectricUtils.powerTotal(
                   chargingStation.getNumberOfPhases(),
-                  chargingStation.getVoltageOut(),
+                  chargingStation.stationInfo.voltageOut!,
                   limit!,
                 );
           break;
@@ -574,10 +574,10 @@ export const getChargingStationConnectorChargingProfilesPowerLimit = (
           limit =
             chargingProfile?.chargingSchedule?.chargingRateUnit === ChargingRateUnitType.WATT
               ? limit
-              : DCElectricUtils.power(chargingStation.getVoltageOut(), limit!);
+              : DCElectricUtils.power(chargingStation.stationInfo.voltageOut!, limit!);
       }
       const connectorMaximumPower =
-        chargingStation.getMaximumPower() / chargingStation.powerDivider;
+        chargingStation.stationInfo.maximumPower! / chargingStation.powerDivider;
       if (limit! > connectorMaximumPower) {
         logger.error(
           `${chargingStation.logPrefix()} ${moduleName}.getChargingStationConnectorChargingProfilesPowerLimit: Charging profile id ${chargingProfile?.chargingProfileId} limit ${limit} is greater than connector id ${connectorId} maximum ${connectorMaximumPower}: %j`,
index 1f1366fa8a4e7416084687062fa6301ee8fba6d4..83300b94c63e914f9382bb1781ec33ccd9be9cd0 100644 (file)
@@ -339,7 +339,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
   ): Promise<void> {
     let response: ResType;
     if (
-      chargingStation.getOcppStrictCompliance() === true &&
+      chargingStation.stationInfo?.ocppStrictCompliance === true &&
       chargingStation.inPendingState() === true &&
       (commandName === OCPP16IncomingRequestCommand.REMOTE_START_TRANSACTION ||
         commandName === OCPP16IncomingRequestCommand.REMOTE_STOP_TRANSACTION)
@@ -357,7 +357,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
     }
     if (
       chargingStation.isRegistered() === true ||
-      (chargingStation.getOcppStrictCompliance() === false &&
+      (chargingStation.stationInfo?.ocppStrictCompliance === false &&
         chargingStation.inUnknownState() === true)
     ) {
       if (
index d731071df7fb7c1ce7db2b730c527dd6e34b5e8f..b238dc66018a50563217065e08f42cfcaf427888 100644 (file)
@@ -199,7 +199,7 @@ export class OCPP16RequestService extends OCPPRequestService {
           ...commandParams,
         } as unknown as Request;
       case OCPP16RequestCommand.STOP_TRANSACTION:
-        chargingStation.getTransactionDataMeterValues() &&
+        chargingStation.stationInfo?.transactionDataMeterValues &&
           (connectorId = chargingStation.getConnectorIdByTransactionId(
             commandParams?.transactionId as number,
           )!);
@@ -211,7 +211,7 @@ export class OCPP16RequestService extends OCPPRequestService {
           idTag: chargingStation.getTransactionIdTag(commandParams?.transactionId as number),
           meterStop: energyActiveImportRegister,
           timestamp: new Date(),
-          ...(chargingStation.getTransactionDataMeterValues() && {
+          ...(chargingStation.stationInfo?.transactionDataMeterValues && {
             transactionData: OCPP16ServiceUtils.buildTransactionDataMeterValues(
               chargingStation.getConnectorStatus(connectorId!)!.transactionBeginMeterValue!,
               OCPP16ServiceUtils.buildTransactionEndMeterValue(
index e978b24fdfee0fcab7a0323383ec87f2f0e595ec..7431246587c034610a98078ceffae3f927024543 100644 (file)
@@ -516,7 +516,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
     if (
       connectorStatus?.transactionRemoteStarted === true &&
       chargingStation.getAuthorizeRemoteTxRequests() === true &&
-      chargingStation.getRemoteAuthorization() === true &&
+      chargingStation.stationInfo?.remoteAuthorization === true &&
       connectorStatus?.idTagLocalAuthorized === false &&
       connectorStatus?.idTagAuthorized === false
     ) {
@@ -629,7 +629,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
           ReservationTerminationReason.TRANSACTION_STARTED,
         );
       }
-      chargingStation.getBeginEndMeterValues() &&
+      chargingStation.stationInfo?.beginEndMeterValues &&
         (await chargingStation.ocppRequestService.requestHandler<
           OCPP16MeterValuesRequest,
           OCPP16MeterValuesResponse
@@ -712,9 +712,9 @@ export class OCPP16ResponseService extends OCPPResponseService {
       );
       return;
     }
-    chargingStation.getBeginEndMeterValues() === true &&
-      chargingStation.getOcppStrictCompliance() === false &&
-      chargingStation.getOutOfOrderEndMeterValues() === true &&
+    chargingStation.stationInfo?.beginEndMeterValues === true &&
+      chargingStation.stationInfo?.ocppStrictCompliance === false &&
+      chargingStation.stationInfo?.outOfOrderEndMeterValues === true &&
       (await chargingStation.ocppRequestService.requestHandler<
         OCPP16MeterValuesRequest,
         OCPP16MeterValuesResponse
index 04cf899f2cd01437a89592b0c4dc7de63fb72bfa..02cbac8d48ae1710c638e592ea4f9b5569ea4f56 100644 (file)
@@ -136,7 +136,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
     if (voltageSampledValueTemplate) {
       const voltageSampledValueTemplateValue = voltageSampledValueTemplate.value
         ? parseInt(voltageSampledValueTemplate.value)
-        : chargingStation.getVoltageOut();
+        : chargingStation.stationInfo.voltageOut!;
       const fluctuationPercent =
         voltageSampledValueTemplate.fluctuationPercent ?? Constants.DEFAULT_FLUCTUATION_PERCENT;
       const voltageMeasurandValue = getRandomFloatFluctuatedRounded(
@@ -145,7 +145,8 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
       );
       if (
         chargingStation.getNumberOfPhases() !== 3 ||
-        (chargingStation.getNumberOfPhases() === 3 && chargingStation.getMainVoltageMeterValues())
+        (chargingStation.getNumberOfPhases() === 3 &&
+          chargingStation.stationInfo?.mainVoltageMeterValues)
       ) {
         meterValue.sampledValue.push(
           OCPP16ServiceUtils.buildSampledValue(voltageSampledValueTemplate, voltageMeasurandValue),
@@ -169,7 +170,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
           const voltagePhaseLineToNeutralSampledValueTemplateValue =
             voltagePhaseLineToNeutralSampledValueTemplate.value
               ? parseInt(voltagePhaseLineToNeutralSampledValueTemplate.value)
-              : chargingStation.getVoltageOut();
+              : chargingStation.stationInfo.voltageOut!;
           const fluctuationPhaseToNeutralPercent =
             voltagePhaseLineToNeutralSampledValueTemplate.fluctuationPercent ??
             Constants.DEFAULT_FLUCTUATION_PERCENT;
@@ -186,7 +187,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
             phaseLineToNeutralValue as OCPP16MeterValuePhase,
           ),
         );
-        if (chargingStation.getPhaseLineToLineVoltageMeterValues()) {
+        if (chargingStation.stationInfo?.phaseLineToLineVoltageMeterValues) {
           const phaseLineToLineValue = `L${phase}-L${
             (phase + 1) % chargingStation.getNumberOfPhases() !== 0
               ? (phase + 1) % chargingStation.getNumberOfPhases()
@@ -265,7 +266,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
       const errMsg = `MeterValues measurand ${
         powerSampledValueTemplate.measurand ??
         OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER
-      }: Unknown ${chargingStation.getCurrentOutType()} currentOutType in template file ${
+      }: Unknown ${chargingStation.stationInfo?.currentOutType} currentOutType in template file ${
         chargingStation.templateFile
       }, cannot calculate ${
         powerSampledValueTemplate.measurand ??
@@ -283,7 +284,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
       const connectorMinimumPowerPerPhase = Math.round(
         connectorMinimumPower / chargingStation.getNumberOfPhases(),
       );
-      switch (chargingStation.getCurrentOutType()) {
+      switch (chargingStation.stationInfo?.currentOutType) {
         case CurrentType.AC:
           if (chargingStation.getNumberOfPhases() === 3) {
             const defaultFluctuatedPowerPerPhase =
@@ -292,7 +293,10 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
                 OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
                   powerSampledValueTemplate.value,
                   connectorMaximumPower / unitDivider,
-                  { limitationEnabled: chargingStation.getCustomValueLimitationMeterValues() },
+                  {
+                    limitationEnabled:
+                      chargingStation.stationInfo?.customValueLimitationMeterValues,
+                  },
                 ) / chargingStation.getNumberOfPhases(),
                 powerSampledValueTemplate.fluctuationPercent ??
                   Constants.DEFAULT_FLUCTUATION_PERCENT,
@@ -303,7 +307,10 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
                 OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
                   powerPerPhaseSampledValueTemplates.L1.value,
                   connectorMaximumPowerPerPhase / unitDivider,
-                  { limitationEnabled: chargingStation.getCustomValueLimitationMeterValues() },
+                  {
+                    limitationEnabled:
+                      chargingStation.stationInfo?.customValueLimitationMeterValues,
+                  },
                 ),
                 powerPerPhaseSampledValueTemplates.L1.fluctuationPercent ??
                   Constants.DEFAULT_FLUCTUATION_PERCENT,
@@ -314,7 +321,10 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
                 OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
                   powerPerPhaseSampledValueTemplates.L2.value,
                   connectorMaximumPowerPerPhase / unitDivider,
-                  { limitationEnabled: chargingStation.getCustomValueLimitationMeterValues() },
+                  {
+                    limitationEnabled:
+                      chargingStation.stationInfo?.customValueLimitationMeterValues,
+                  },
                 ),
                 powerPerPhaseSampledValueTemplates.L2.fluctuationPercent ??
                   Constants.DEFAULT_FLUCTUATION_PERCENT,
@@ -325,7 +335,10 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
                 OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
                   powerPerPhaseSampledValueTemplates.L3.value,
                   connectorMaximumPowerPerPhase / unitDivider,
-                  { limitationEnabled: chargingStation.getCustomValueLimitationMeterValues() },
+                  {
+                    limitationEnabled:
+                      chargingStation.stationInfo?.customValueLimitationMeterValues,
+                  },
                 ),
                 powerPerPhaseSampledValueTemplates.L3.fluctuationPercent ??
                   Constants.DEFAULT_FLUCTUATION_PERCENT,
@@ -357,7 +370,10 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
                   OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
                     powerSampledValueTemplate.value,
                     connectorMaximumPower / unitDivider,
-                    { limitationEnabled: chargingStation.getCustomValueLimitationMeterValues() },
+                    {
+                      limitationEnabled:
+                        chargingStation.stationInfo?.customValueLimitationMeterValues,
+                    },
                   ),
                   powerSampledValueTemplate.fluctuationPercent ??
                     Constants.DEFAULT_FLUCTUATION_PERCENT,
@@ -380,7 +396,10 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
                 OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
                   powerSampledValueTemplate.value,
                   connectorMaximumPower / unitDivider,
-                  { limitationEnabled: chargingStation.getCustomValueLimitationMeterValues() },
+                  {
+                    limitationEnabled:
+                      chargingStation.stationInfo?.customValueLimitationMeterValues,
+                  },
                 ),
                 powerSampledValueTemplate.fluctuationPercent ??
                   Constants.DEFAULT_FLUCTUATION_PERCENT,
@@ -501,7 +520,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
       const errMsg = `MeterValues measurand ${
         currentSampledValueTemplate.measurand ??
         OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER
-      }: Unknown ${chargingStation.getCurrentOutType()} currentOutType in template file ${
+      }: Unknown ${chargingStation.stationInfo?.currentOutType} currentOutType in template file ${
         chargingStation.templateFile
       }, cannot calculate ${
         currentSampledValueTemplate.measurand ??
@@ -512,12 +531,12 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
         chargingStation.getConnectorMaximumAvailablePower(connectorId);
       const connectorMinimumAmperage = currentSampledValueTemplate.minimumValue ?? 0;
       let connectorMaximumAmperage: number;
-      switch (chargingStation.getCurrentOutType()) {
+      switch (chargingStation.stationInfo?.currentOutType) {
         case CurrentType.AC:
           connectorMaximumAmperage = ACElectricUtils.amperagePerPhaseFromPower(
             chargingStation.getNumberOfPhases(),
             connectorMaximumAvailablePower,
-            chargingStation.getVoltageOut(),
+            chargingStation.stationInfo.voltageOut!,
           );
           if (chargingStation.getNumberOfPhases() === 3) {
             const defaultFluctuatedAmperagePerPhase =
@@ -526,7 +545,10 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
                 OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
                   currentSampledValueTemplate.value,
                   connectorMaximumAmperage,
-                  { limitationEnabled: chargingStation.getCustomValueLimitationMeterValues() },
+                  {
+                    limitationEnabled:
+                      chargingStation.stationInfo?.customValueLimitationMeterValues,
+                  },
                 ),
                 currentSampledValueTemplate.fluctuationPercent ??
                   Constants.DEFAULT_FLUCTUATION_PERCENT,
@@ -537,7 +559,10 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
                 OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
                   currentPerPhaseSampledValueTemplates.L1.value,
                   connectorMaximumAmperage,
-                  { limitationEnabled: chargingStation.getCustomValueLimitationMeterValues() },
+                  {
+                    limitationEnabled:
+                      chargingStation.stationInfo?.customValueLimitationMeterValues,
+                  },
                 ),
                 currentPerPhaseSampledValueTemplates.L1.fluctuationPercent ??
                   Constants.DEFAULT_FLUCTUATION_PERCENT,
@@ -548,7 +573,10 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
                 OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
                   currentPerPhaseSampledValueTemplates.L2.value,
                   connectorMaximumAmperage,
-                  { limitationEnabled: chargingStation.getCustomValueLimitationMeterValues() },
+                  {
+                    limitationEnabled:
+                      chargingStation.stationInfo?.customValueLimitationMeterValues,
+                  },
                 ),
                 currentPerPhaseSampledValueTemplates.L2.fluctuationPercent ??
                   Constants.DEFAULT_FLUCTUATION_PERCENT,
@@ -559,7 +587,10 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
                 OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
                   currentPerPhaseSampledValueTemplates.L3.value,
                   connectorMaximumAmperage,
-                  { limitationEnabled: chargingStation.getCustomValueLimitationMeterValues() },
+                  {
+                    limitationEnabled:
+                      chargingStation.stationInfo?.customValueLimitationMeterValues,
+                  },
                 ),
                 currentPerPhaseSampledValueTemplates.L3.fluctuationPercent ??
                   Constants.DEFAULT_FLUCTUATION_PERCENT,
@@ -582,7 +613,10 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
                   OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
                     currentSampledValueTemplate.value,
                     connectorMaximumAmperage,
-                    { limitationEnabled: chargingStation.getCustomValueLimitationMeterValues() },
+                    {
+                      limitationEnabled:
+                        chargingStation.stationInfo?.customValueLimitationMeterValues,
+                    },
                   ),
                   currentSampledValueTemplate.fluctuationPercent ??
                     Constants.DEFAULT_FLUCTUATION_PERCENT,
@@ -600,14 +634,17 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
         case CurrentType.DC:
           connectorMaximumAmperage = DCElectricUtils.amperage(
             connectorMaximumAvailablePower,
-            chargingStation.getVoltageOut(),
+            chargingStation.stationInfo.voltageOut!,
           );
           currentMeasurandValues.allPhases = currentSampledValueTemplate.value
             ? getRandomFloatFluctuatedRounded(
                 OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
                   currentSampledValueTemplate.value,
                   connectorMaximumAmperage,
-                  { limitationEnabled: chargingStation.getCustomValueLimitationMeterValues() },
+                  {
+                    limitationEnabled:
+                      chargingStation.stationInfo?.customValueLimitationMeterValues,
+                  },
                 ),
                 currentSampledValueTemplate.fluctuationPercent ??
                   Constants.DEFAULT_FLUCTUATION_PERCENT,
@@ -703,7 +740,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
               energySampledValueTemplate.value,
               connectorMaximumEnergyRounded,
               {
-                limitationEnabled: chargingStation.getCustomValueLimitationMeterValues(),
+                limitationEnabled: chargingStation.stationInfo?.customValueLimitationMeterValues,
                 unitMultiplier: unitDivider,
               },
             ),
index 6344d36d01aa607e7aed7f3523c11a1da96f440e..0d657d99f7bd67b365660c3e2888653157485e5c 100644 (file)
@@ -55,7 +55,7 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService {
   ): Promise<void> {
     let response: ResType;
     if (
-      chargingStation.getOcppStrictCompliance() === true &&
+      chargingStation.stationInfo?.ocppStrictCompliance === true &&
       chargingStation.inPendingState() === true &&
       (commandName === OCPP20IncomingRequestCommand.REQUEST_START_TRANSACTION ||
         commandName === OCPP20IncomingRequestCommand.REQUEST_STOP_TRANSACTION)
@@ -73,7 +73,7 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService {
     }
     if (
       chargingStation.isRegistered() === true ||
-      (chargingStation.getOcppStrictCompliance() === false &&
+      (chargingStation.stationInfo?.ocppStrictCompliance === false &&
         chargingStation.inUnknownState() === true)
     ) {
       if (
index fd4d8807daa155662a82ce2d1f55e7ae9e659695..28de507774a281aeeb0d32b4d17b1348b45d50c5 100644 (file)
@@ -89,7 +89,7 @@ export abstract class OCPPIncomingRequestService extends AsyncResource {
     schema: JSONSchemaType<T>,
     payload: T,
   ): boolean {
-    if (chargingStation.getOcppStrictCompliance() === false) {
+    if (chargingStation.stationInfo?.ocppStrictCompliance === false) {
       return true;
     }
     if (this.jsonValidateFunctions.has(commandName) === false) {
index bcbbe639b8dcc8920855f83097ec71afc0353576..98c3081155bd2f350fe3a686c7909cd524166b52 100644 (file)
@@ -203,7 +203,7 @@ export abstract class OCPPRequestService {
     commandName: RequestCommand | IncomingRequestCommand,
     payload: T,
   ): boolean {
-    if (chargingStation.getOcppStrictCompliance() === false) {
+    if (chargingStation.stationInfo?.ocppStrictCompliance === false) {
       return true;
     }
     if (this.jsonSchemas.has(commandName as RequestCommand) === false) {
@@ -242,7 +242,7 @@ export abstract class OCPPRequestService {
     commandName: RequestCommand | IncomingRequestCommand,
     payload: T,
   ): boolean {
-    if (chargingStation.getOcppStrictCompliance() === false) {
+    if (chargingStation.stationInfo?.ocppStrictCompliance === false) {
       return true;
     }
     if (
@@ -307,7 +307,7 @@ export abstract class OCPPRequestService {
     if (
       (chargingStation.inUnknownState() === true &&
         commandName === RequestCommand.BOOT_NOTIFICATION) ||
-      (chargingStation.getOcppStrictCompliance() === false &&
+      (chargingStation.stationInfo?.ocppStrictCompliance === false &&
         chargingStation.inUnknownState() === true) ||
       chargingStation.inAcceptedState() === true ||
       (chargingStation.inPendingState() === true &&
@@ -325,7 +325,7 @@ export abstract class OCPPRequestService {
            * @param requestPayload -
            */
           const responseCallback = (payload: JsonType, requestPayload: JsonType): void => {
-            if (chargingStation.getEnableStatistics() === true) {
+            if (chargingStation.stationInfo?.enableStatistics === true) {
               chargingStation.performanceStatistics?.addRequestStatistic(
                 commandName,
                 MessageType.CALL_RESULT_MESSAGE,
@@ -357,7 +357,10 @@ export abstract class OCPPRequestService {
            * @param requestStatistic -
            */
           const errorCallback = (error: OCPPError, requestStatistic = true): void => {
-            if (requestStatistic === true && chargingStation.getEnableStatistics() === true) {
+            if (
+              requestStatistic === true &&
+              chargingStation.stationInfo?.enableStatistics === true
+            ) {
               chargingStation.performanceStatistics?.addRequestStatistic(
                 commandName,
                 MessageType.CALL_ERROR_MESSAGE,
@@ -374,7 +377,7 @@ export abstract class OCPPRequestService {
             reject(error);
           };
 
-          if (chargingStation.getEnableStatistics() === true) {
+          if (chargingStation.stationInfo?.enableStatistics === true) {
             chargingStation.performanceStatistics?.addRequestStatistic(commandName, messageType);
           }
           const messageToSend = this.buildMessageToSend(
index 1bc73bc83cd8071f3c42af848deb44d1ac10af03..0aedbb1eebb5b6a17a2abe94b2b85641c68c07e9 100644 (file)
@@ -68,7 +68,7 @@ export abstract class OCPPResponseService {
     schema: JSONSchemaType<T>,
     payload: T,
   ): boolean {
-    if (chargingStation.getOcppStrictCompliance() === false) {
+    if (chargingStation.stationInfo?.ocppStrictCompliance === false) {
       return true;
     }
     if (this.jsonRequestValidateFunctions.has(commandName) === false) {
index ef16bfb8703302c74488af11ff635b8c6da4dd2d..ee4134bb0a192f8db9f27075557f1e176ad4d58c 100644 (file)
@@ -173,7 +173,7 @@ export class OCPPServiceUtils {
     status: ConnectorStatusEnum,
     evseId?: number,
   ): StatusNotificationRequest {
-    switch (chargingStation.stationInfo.ocppVersion ?? OCPPVersion.VERSION_16) {
+    switch (chargingStation.stationInfo?.ocppVersion) {
       case OCPPVersion.VERSION_16:
         return {
           connectorId,
@@ -233,7 +233,10 @@ export class OCPPServiceUtils {
     connectorId: number,
     idTag: string,
   ): Promise<boolean> {
-    if (!chargingStation.getLocalAuthListEnabled() && !chargingStation.getRemoteAuthorization()) {
+    if (
+      !chargingStation.getLocalAuthListEnabled() &&
+      !chargingStation.stationInfo?.remoteAuthorization
+    ) {
       logger.warn(
         `${chargingStation.logPrefix()} The charging station expects to authorize RFID tags but nor local authorization nor remote authorization are enabled. Misbehavior may occur`,
       );
@@ -246,7 +249,7 @@ export class OCPPServiceUtils {
       connectorStatus.localAuthorizeIdTag = idTag;
       connectorStatus.idTagLocalAuthorized = true;
       return true;
-    } else if (chargingStation.getRemoteAuthorization()) {
+    } else if (chargingStation.stationInfo?.remoteAuthorization) {
       return await OCPPServiceUtils.isIdTagRemoteAuthorized(chargingStation, connectorId, idTag);
     }
     return false;
@@ -259,7 +262,7 @@ export class OCPPServiceUtils {
   ): boolean {
     const fromStatus = chargingStation.getConnectorStatus(connectorId)!.status;
     let transitionAllowed = false;
-    switch (chargingStation.stationInfo.ocppVersion) {
+    switch (chargingStation.stationInfo?.ocppVersion) {
       case OCPPVersion.VERSION_16:
         if (
           (connectorId === 0 &&
@@ -292,14 +295,13 @@ export class OCPPServiceUtils {
       default:
         throw new BaseError(
           // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
-          `Cannot check connector status transition: OCPP version ${chargingStation.stationInfo.ocppVersion} not supported`,
+          `Cannot check connector status transition: OCPP version ${chargingStation.stationInfo?.ocppVersion} not supported`,
         );
     }
     if (transitionAllowed === false) {
       logger.warn(
-        `${chargingStation.logPrefix()} OCPP ${
-          chargingStation.stationInfo.ocppVersion
-        } connector id ${connectorId} status transition from '${
+        `${chargingStation.logPrefix()} OCPP ${chargingStation.stationInfo
+          ?.ocppVersion} connector id ${connectorId} status transition from '${
           chargingStation.getConnectorStatus(connectorId)!.status
         }' to '${status}' is not allowed`,
       );