refactor: factor out OCPP params handling helpers
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 18 Jul 2023 18:39:04 +0000 (20:39 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 18 Jul 2023 18:39:04 +0000 (20:39 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/ChargingStationConfigurationUtils.ts
src/charging-station/broadcast-channel/ChargingStationWorkerBroadcastChannel.ts
src/charging-station/index.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
src/charging-station/ocpp/1.6/OCPP16ResponseService.ts
src/charging-station/ocpp/2.0/OCPP20ResponseService.ts
src/charging-station/ocpp/OCPPServiceUtils.ts

index bca03a793980ba72304075d3882f7d63e8af4fda..dd5bdda05c6ea04370c769c8c2fe78e1890d9457 100644 (file)
@@ -19,7 +19,12 @@ import { type RawData, WebSocket } from 'ws';
 
 import { AutomaticTransactionGenerator } from './AutomaticTransactionGenerator';
 import { ChargingStationWorkerBroadcastChannel } from './broadcast-channel/ChargingStationWorkerBroadcastChannel';
-import { ChargingStationConfigurationUtils } from './ChargingStationConfigurationUtils';
+import {
+  addConfigurationKey,
+  deleteConfigurationKey,
+  getConfigurationKey,
+  setConfigurationKeyValue,
+} from './ChargingStationConfigurationUtils';
 import {
   buildConnectorsMap,
   checkConnectorsConfiguration,
@@ -212,16 +217,8 @@ export class ChargingStation {
       `${
         this.getSupervisionUrlOcppConfiguration() &&
         isNotEmptyString(this.getSupervisionUrlOcppKey()) &&
-        isNotEmptyString(
-          ChargingStationConfigurationUtils.getConfigurationKey(
-            this,
-            this.getSupervisionUrlOcppKey(),
-          )?.value,
-        )
-          ? ChargingStationConfigurationUtils.getConfigurationKey(
-              this,
-              this.getSupervisionUrlOcppKey(),
-            )!.value
+        isNotEmptyString(getConfigurationKey(this, this.getSupervisionUrlOcppKey())?.value)
+          ? getConfigurationKey(this, this.getSupervisionUrlOcppKey())!.value
           : this.configuredSupervisionUrl.href
       }/${this.stationInfo.chargingStationId}`,
     );
@@ -500,7 +497,7 @@ export class ChargingStation {
   }
 
   public getAuthorizeRemoteTxRequests(): boolean {
-    const authorizeRemoteTxRequests = ChargingStationConfigurationUtils.getConfigurationKey(
+    const authorizeRemoteTxRequests = getConfigurationKey(
       this,
       StandardParametersKey.AuthorizeRemoteTxRequests,
     );
@@ -508,7 +505,7 @@ export class ChargingStation {
   }
 
   public getLocalAuthListEnabled(): boolean {
-    const localAuthListEnabled = ChargingStationConfigurationUtils.getConfigurationKey(
+    const localAuthListEnabled = getConfigurationKey(
       this,
       StandardParametersKey.LocalAuthListEnabled,
     );
@@ -516,17 +513,11 @@ export class ChargingStation {
   }
 
   public getHeartbeatInterval(): number {
-    const HeartbeatInterval = ChargingStationConfigurationUtils.getConfigurationKey(
-      this,
-      StandardParametersKey.HeartbeatInterval,
-    );
+    const HeartbeatInterval = getConfigurationKey(this, StandardParametersKey.HeartbeatInterval);
     if (HeartbeatInterval) {
       return convertToInt(HeartbeatInterval.value) * 1000;
     }
-    const HeartBeatInterval = ChargingStationConfigurationUtils.getConfigurationKey(
-      this,
-      StandardParametersKey.HeartBeatInterval,
-    );
+    const HeartBeatInterval = getConfigurationKey(this, StandardParametersKey.HeartBeatInterval);
     if (HeartBeatInterval) {
       return convertToInt(HeartBeatInterval.value) * 1000;
     }
@@ -544,11 +535,7 @@ export class ChargingStation {
       this.getSupervisionUrlOcppConfiguration() &&
       isNotEmptyString(this.getSupervisionUrlOcppKey())
     ) {
-      ChargingStationConfigurationUtils.setConfigurationKeyValue(
-        this,
-        this.getSupervisionUrlOcppKey(),
-        url,
-      );
+      setConfigurationKeyValue(this, this.getSupervisionUrlOcppKey(), url);
     } else {
       this.stationInfo.supervisionUrls = url;
       this.saveStationInfo();
@@ -771,7 +758,7 @@ export class ChargingStation {
   }
 
   public hasFeatureProfile(featureProfile: SupportedFeatureProfiles): boolean | undefined {
-    return ChargingStationConfigurationUtils.getConfigurationKey(
+    return getConfigurationKey(
       this,
       StandardParametersKey.SupportedFeatureProfiles,
     )?.value?.includes(featureProfile);
@@ -948,10 +935,7 @@ export class ChargingStation {
 
   public getReservationOnConnectorId0Enabled(): boolean {
     return convertToBoolean(
-      ChargingStationConfigurationUtils.getConfigurationKey(
-        this,
-        StandardParametersKey.ReserveConnectorZeroSupported,
-      )!.value,
+      getConfigurationKey(this, StandardParametersKey.ReserveConnectorZeroSupported)!.value,
     );
   }
 
@@ -1376,37 +1360,18 @@ export class ChargingStation {
   }
 
   private initializeOcppConfiguration(): void {
-    if (
-      !ChargingStationConfigurationUtils.getConfigurationKey(
-        this,
-        StandardParametersKey.HeartbeatInterval,
-      )
-    ) {
-      ChargingStationConfigurationUtils.addConfigurationKey(
-        this,
-        StandardParametersKey.HeartbeatInterval,
-        '0',
-      );
+    if (!getConfigurationKey(this, StandardParametersKey.HeartbeatInterval)) {
+      addConfigurationKey(this, StandardParametersKey.HeartbeatInterval, '0');
     }
-    if (
-      !ChargingStationConfigurationUtils.getConfigurationKey(
-        this,
-        StandardParametersKey.HeartBeatInterval,
-      )
-    ) {
-      ChargingStationConfigurationUtils.addConfigurationKey(
-        this,
-        StandardParametersKey.HeartBeatInterval,
-        '0',
-        { visible: false },
-      );
+    if (!getConfigurationKey(this, StandardParametersKey.HeartBeatInterval)) {
+      addConfigurationKey(this, StandardParametersKey.HeartBeatInterval, '0', { visible: false });
     }
     if (
       this.getSupervisionUrlOcppConfiguration() &&
       isNotEmptyString(this.getSupervisionUrlOcppKey()) &&
-      !ChargingStationConfigurationUtils.getConfigurationKey(this, this.getSupervisionUrlOcppKey())
+      !getConfigurationKey(this, this.getSupervisionUrlOcppKey())
     ) {
-      ChargingStationConfigurationUtils.addConfigurationKey(
+      addConfigurationKey(
         this,
         this.getSupervisionUrlOcppKey(),
         this.configuredSupervisionUrl.href,
@@ -1415,22 +1380,15 @@ export class ChargingStation {
     } else if (
       !this.getSupervisionUrlOcppConfiguration() &&
       isNotEmptyString(this.getSupervisionUrlOcppKey()) &&
-      ChargingStationConfigurationUtils.getConfigurationKey(this, this.getSupervisionUrlOcppKey())
+      getConfigurationKey(this, this.getSupervisionUrlOcppKey())
     ) {
-      ChargingStationConfigurationUtils.deleteConfigurationKey(
-        this,
-        this.getSupervisionUrlOcppKey(),
-        { save: false },
-      );
+      deleteConfigurationKey(this, this.getSupervisionUrlOcppKey(), { save: false });
     }
     if (
       isNotEmptyString(this.stationInfo?.amperageLimitationOcppKey) &&
-      !ChargingStationConfigurationUtils.getConfigurationKey(
-        this,
-        this.stationInfo.amperageLimitationOcppKey!,
-      )
+      !getConfigurationKey(this, this.stationInfo.amperageLimitationOcppKey!)
     ) {
-      ChargingStationConfigurationUtils.addConfigurationKey(
+      addConfigurationKey(
         this,
         this.stationInfo.amperageLimitationOcppKey!,
         (
@@ -1438,43 +1396,28 @@ export class ChargingStation {
         ).toString(),
       );
     }
-    if (
-      !ChargingStationConfigurationUtils.getConfigurationKey(
-        this,
-        StandardParametersKey.SupportedFeatureProfiles,
-      )
-    ) {
-      ChargingStationConfigurationUtils.addConfigurationKey(
+    if (!getConfigurationKey(this, StandardParametersKey.SupportedFeatureProfiles)) {
+      addConfigurationKey(
         this,
         StandardParametersKey.SupportedFeatureProfiles,
         `${SupportedFeatureProfiles.Core},${SupportedFeatureProfiles.FirmwareManagement},${SupportedFeatureProfiles.LocalAuthListManagement},${SupportedFeatureProfiles.SmartCharging},${SupportedFeatureProfiles.RemoteTrigger}`,
       );
     }
-    ChargingStationConfigurationUtils.addConfigurationKey(
+    addConfigurationKey(
       this,
       StandardParametersKey.NumberOfConnectors,
       this.getNumberOfConnectors().toString(),
       { readonly: true },
       { overwrite: true },
     );
-    if (
-      !ChargingStationConfigurationUtils.getConfigurationKey(
-        this,
-        StandardParametersKey.MeterValuesSampledData,
-      )
-    ) {
-      ChargingStationConfigurationUtils.addConfigurationKey(
+    if (!getConfigurationKey(this, StandardParametersKey.MeterValuesSampledData)) {
+      addConfigurationKey(
         this,
         StandardParametersKey.MeterValuesSampledData,
         MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER,
       );
     }
-    if (
-      !ChargingStationConfigurationUtils.getConfigurationKey(
-        this,
-        StandardParametersKey.ConnectorPhaseRotation,
-      )
-    ) {
+    if (!getConfigurationKey(this, StandardParametersKey.ConnectorPhaseRotation)) {
       const connectorsPhaseRotation: string[] = [];
       if (this.hasEvses) {
         for (const evseStatus of this.evses.values()) {
@@ -1491,47 +1434,25 @@ export class ChargingStation {
           );
         }
       }
-      ChargingStationConfigurationUtils.addConfigurationKey(
+      addConfigurationKey(
         this,
         StandardParametersKey.ConnectorPhaseRotation,
         connectorsPhaseRotation.toString(),
       );
     }
-    if (
-      !ChargingStationConfigurationUtils.getConfigurationKey(
-        this,
-        StandardParametersKey.AuthorizeRemoteTxRequests,
-      )
-    ) {
-      ChargingStationConfigurationUtils.addConfigurationKey(
-        this,
-        StandardParametersKey.AuthorizeRemoteTxRequests,
-        'true',
-      );
+    if (!getConfigurationKey(this, StandardParametersKey.AuthorizeRemoteTxRequests)) {
+      addConfigurationKey(this, StandardParametersKey.AuthorizeRemoteTxRequests, 'true');
     }
     if (
-      !ChargingStationConfigurationUtils.getConfigurationKey(
-        this,
-        StandardParametersKey.LocalAuthListEnabled,
-      ) &&
-      ChargingStationConfigurationUtils.getConfigurationKey(
-        this,
-        StandardParametersKey.SupportedFeatureProfiles,
-      )?.value?.includes(SupportedFeatureProfiles.LocalAuthListManagement)
-    ) {
-      ChargingStationConfigurationUtils.addConfigurationKey(
-        this,
-        StandardParametersKey.LocalAuthListEnabled,
-        'false',
-      );
-    }
-    if (
-      !ChargingStationConfigurationUtils.getConfigurationKey(
-        this,
-        StandardParametersKey.ConnectionTimeOut,
+      !getConfigurationKey(this, StandardParametersKey.LocalAuthListEnabled) &&
+      getConfigurationKey(this, StandardParametersKey.SupportedFeatureProfiles)?.value?.includes(
+        SupportedFeatureProfiles.LocalAuthListManagement,
       )
     ) {
-      ChargingStationConfigurationUtils.addConfigurationKey(
+      addConfigurationKey(this, StandardParametersKey.LocalAuthListEnabled, 'false');
+    }
+    if (!getConfigurationKey(this, StandardParametersKey.ConnectionTimeOut)) {
+      addConfigurationKey(
         this,
         StandardParametersKey.ConnectionTimeOut,
         Constants.DEFAULT_CONNECTION_TIMEOUT.toString(),
@@ -2167,19 +2088,10 @@ export class ChargingStation {
 
   // 0 for disabling
   private getConnectionTimeout(): number {
-    if (
-      ChargingStationConfigurationUtils.getConfigurationKey(
-        this,
-        StandardParametersKey.ConnectionTimeOut,
-      )
-    ) {
+    if (getConfigurationKey(this, StandardParametersKey.ConnectionTimeOut)) {
       return (
-        parseInt(
-          ChargingStationConfigurationUtils.getConfigurationKey(
-            this,
-            StandardParametersKey.ConnectionTimeOut,
-          )!.value!,
-        ) ?? Constants.DEFAULT_CONNECTION_TIMEOUT
+        parseInt(getConfigurationKey(this, StandardParametersKey.ConnectionTimeOut)!.value!) ??
+        Constants.DEFAULT_CONNECTION_TIMEOUT
       );
     }
     return Constants.DEFAULT_CONNECTION_TIMEOUT;
@@ -2222,17 +2134,11 @@ export class ChargingStation {
   private getAmperageLimitation(): number | undefined {
     if (
       isNotEmptyString(this.stationInfo?.amperageLimitationOcppKey) &&
-      ChargingStationConfigurationUtils.getConfigurationKey(
-        this,
-        this.stationInfo.amperageLimitationOcppKey!,
-      )
+      getConfigurationKey(this, this.stationInfo.amperageLimitationOcppKey!)
     ) {
       return (
         convertToInt(
-          ChargingStationConfigurationUtils.getConfigurationKey(
-            this,
-            this.stationInfo.amperageLimitationOcppKey!,
-          )?.value,
+          getConfigurationKey(this, this.stationInfo.amperageLimitationOcppKey!)?.value,
         ) / getAmperageLimitationUnitDivider(this.stationInfo)
       );
     }
@@ -2351,16 +2257,11 @@ export class ChargingStation {
   }
 
   private startWebSocketPing(): void {
-    const webSocketPingInterval: number = ChargingStationConfigurationUtils.getConfigurationKey(
+    const webSocketPingInterval: number = getConfigurationKey(
       this,
       StandardParametersKey.WebSocketPingInterval,
     )
-      ? convertToInt(
-          ChargingStationConfigurationUtils.getConfigurationKey(
-            this,
-            StandardParametersKey.WebSocketPingInterval,
-          )?.value,
-        )
+      ? convertToInt(getConfigurationKey(this, StandardParametersKey.WebSocketPingInterval)?.value)
       : 0;
     if (webSocketPingInterval > 0 && !this.webSocketPingSetInterval) {
       this.webSocketPingSetInterval = setInterval(() => {
index b56411e310b13e32473afb4a3bc3290a786f87cc..39606b66e1ea8d08cacc61b53d58607d53d9c73d 100644 (file)
@@ -16,110 +16,96 @@ interface AddConfigurationKeyParams {
   save?: boolean;
 }
 
-export class ChargingStationConfigurationUtils {
-  private constructor() {
-    // This is intentional
-  }
-
-  public static getConfigurationKey(
-    chargingStation: ChargingStation,
-    key: ConfigurationKeyType,
-    caseInsensitive = false,
-  ): ConfigurationKey | undefined {
-    return chargingStation.ocppConfiguration?.configurationKey?.find((configElement) => {
-      if (caseInsensitive) {
-        return configElement.key.toLowerCase() === key.toLowerCase();
-      }
-      return configElement.key === key;
-    });
-  }
+export const getConfigurationKey = (
+  chargingStation: ChargingStation,
+  key: ConfigurationKeyType,
+  caseInsensitive = false,
+): ConfigurationKey | undefined => {
+  return chargingStation.ocppConfiguration?.configurationKey?.find((configElement) => {
+    if (caseInsensitive) {
+      return configElement.key.toLowerCase() === key.toLowerCase();
+    }
+    return configElement.key === key;
+  });
+};
 
-  public static addConfigurationKey(
-    chargingStation: ChargingStation,
-    key: ConfigurationKeyType,
-    value: string,
-    options: ConfigurationKeyOptions = {
+export const addConfigurationKey = (
+  chargingStation: ChargingStation,
+  key: ConfigurationKeyType,
+  value: string,
+  options: ConfigurationKeyOptions = {
+    readonly: false,
+    visible: true,
+    reboot: false,
+  },
+  params: AddConfigurationKeyParams = { overwrite: false, save: false },
+): void => {
+  options = {
+    ...{
       readonly: false,
       visible: true,
       reboot: false,
     },
-    params: AddConfigurationKeyParams = { overwrite: false, save: false },
-  ): void {
-    options = {
-      ...{
-        readonly: false,
-        visible: true,
-        reboot: false,
-      },
-      ...options,
-    };
-    params = { ...{ overwrite: false, save: false }, ...params };
-    let keyFound = ChargingStationConfigurationUtils.getConfigurationKey(chargingStation, key);
-    if (keyFound && params?.overwrite) {
-      ChargingStationConfigurationUtils.deleteConfigurationKey(chargingStation, keyFound.key, {
-        save: false,
-      });
-      keyFound = undefined;
-    }
-    if (!keyFound) {
-      chargingStation.ocppConfiguration?.configurationKey?.push({
-        key,
-        readonly: options.readonly!,
-        value,
-        visible: options.visible,
-        reboot: options.reboot,
-      });
-      params?.save && chargingStation.saveOcppConfiguration();
-    } else {
-      logger.error(
-        `${chargingStation.logPrefix()} Trying to add an already existing configuration key: %j`,
-        keyFound,
-      );
-    }
+    ...options,
+  };
+  params = { ...{ overwrite: false, save: false }, ...params };
+  let keyFound = getConfigurationKey(chargingStation, key);
+  if (keyFound && params?.overwrite) {
+    deleteConfigurationKey(chargingStation, keyFound.key, {
+      save: false,
+    });
+    keyFound = undefined;
   }
-
-  public static setConfigurationKeyValue(
-    chargingStation: ChargingStation,
-    key: ConfigurationKeyType,
-    value: string,
-    caseInsensitive = false,
-  ): void {
-    const keyFound = ChargingStationConfigurationUtils.getConfigurationKey(
-      chargingStation,
+  if (!keyFound) {
+    chargingStation.ocppConfiguration?.configurationKey?.push({
       key,
-      caseInsensitive,
+      readonly: options.readonly!,
+      value,
+      visible: options.visible,
+      reboot: options.reboot,
+    });
+    params?.save && chargingStation.saveOcppConfiguration();
+  } else {
+    logger.error(
+      `${chargingStation.logPrefix()} Trying to add an already existing configuration key: %j`,
+      keyFound,
     );
-    if (keyFound) {
-      chargingStation.ocppConfiguration!.configurationKey![
-        chargingStation.ocppConfiguration!.configurationKey!.indexOf(keyFound)
-      ].value = value;
-      chargingStation.saveOcppConfiguration();
-    } else {
-      logger.error(
-        `${chargingStation.logPrefix()} Trying to set a value on a non existing configuration key: %j`,
-        { key, value },
-      );
-    }
   }
+};
 
-  public static deleteConfigurationKey(
-    chargingStation: ChargingStation,
-    key: ConfigurationKeyType,
-    params: DeleteConfigurationKeyParams = { save: true, caseInsensitive: false },
-  ): ConfigurationKey[] | undefined {
-    params = { ...{ save: true, caseInsensitive: false }, ...params };
-    const keyFound = ChargingStationConfigurationUtils.getConfigurationKey(
-      chargingStation,
-      key,
-      params?.caseInsensitive,
+export const setConfigurationKeyValue = (
+  chargingStation: ChargingStation,
+  key: ConfigurationKeyType,
+  value: string,
+  caseInsensitive = false,
+): void => {
+  const keyFound = getConfigurationKey(chargingStation, key, caseInsensitive);
+  if (keyFound) {
+    chargingStation.ocppConfiguration!.configurationKey![
+      chargingStation.ocppConfiguration!.configurationKey!.indexOf(keyFound)
+    ].value = value;
+    chargingStation.saveOcppConfiguration();
+  } else {
+    logger.error(
+      `${chargingStation.logPrefix()} Trying to set a value on a non existing configuration key: %j`,
+      { key, value },
     );
-    if (keyFound) {
-      const deletedConfigurationKey = chargingStation.ocppConfiguration?.configurationKey?.splice(
-        chargingStation.ocppConfiguration.configurationKey.indexOf(keyFound),
-        1,
-      );
-      params?.save && chargingStation.saveOcppConfiguration();
-      return deletedConfigurationKey;
-    }
   }
-}
+};
+
+export const deleteConfigurationKey = (
+  chargingStation: ChargingStation,
+  key: ConfigurationKeyType,
+  params: DeleteConfigurationKeyParams = { save: true, caseInsensitive: false },
+): ConfigurationKey[] | undefined => {
+  params = { ...{ save: true, caseInsensitive: false }, ...params };
+  const keyFound = getConfigurationKey(chargingStation, key, params?.caseInsensitive);
+  if (keyFound) {
+    const deletedConfigurationKey = chargingStation.ocppConfiguration?.configurationKey?.splice(
+      chargingStation.ocppConfiguration.configurationKey.indexOf(keyFound),
+      1,
+    );
+    params?.save && chargingStation.saveOcppConfiguration();
+    return deletedConfigurationKey;
+  }
+};
index 84d6961e56cbde3acc4b1e5302e9d0dbed647c6b..bb484be74eaf9e96f0e9c1eee7869d30a32229bd 100644 (file)
@@ -36,7 +36,7 @@ import {
 } from '../../types';
 import { Constants, convertToInt, isEmptyObject, isNullOrUndefined, logger } from '../../utils';
 import type { ChargingStation } from '../ChargingStation';
-import { ChargingStationConfigurationUtils } from '../ChargingStationConfigurationUtils';
+import { getConfigurationKey } from '../ChargingStationConfigurationUtils';
 import { OCPP16ServiceUtils } from '../ocpp';
 
 const moduleName = 'ChargingStationWorkerBroadcastChannel';
@@ -173,11 +173,10 @@ export class ChargingStationWorkerBroadcastChannel extends WorkerBroadcastChanne
       [
         BroadcastChannelProcedureName.METER_VALUES,
         async (requestPayload?: BroadcastChannelRequestPayload) => {
-          const configuredMeterValueSampleInterval =
-            ChargingStationConfigurationUtils.getConfigurationKey(
-              chargingStation,
-              StandardParametersKey.MeterValueSampleInterval,
-            );
+          const configuredMeterValueSampleInterval = getConfigurationKey(
+            chargingStation,
+            StandardParametersKey.MeterValueSampleInterval,
+          );
           return this.chargingStation.ocppRequestService.requestHandler<
             MeterValuesRequest,
             MeterValuesResponse
index 49ae434afdc1febc503ef84c612285e538ec988d..7e992fe2d1d91cd273325e4a63830b5691dffc82 100644 (file)
@@ -1,4 +1,8 @@
 export { Bootstrap } from './Bootstrap';
 export type { ChargingStation } from './ChargingStation';
-export { ChargingStationConfigurationUtils } from './ChargingStationConfigurationUtils';
+export {
+  addConfigurationKey,
+  getConfigurationKey,
+  setConfigurationKeyValue,
+} from './ChargingStationConfigurationUtils';
 export { getIdTagsFile, checkChargingStation, resetConnectorStatus } from './ChargingStationUtils';
index 5fa160c3fa453ace012e645d4039f5efda0d1b25..163b006f5bdac0fea1d2ed00396715d3fc26ecd6 100644 (file)
@@ -12,8 +12,9 @@ import { OCPP16Constants } from './OCPP16Constants';
 import { OCPP16ServiceUtils } from './OCPP16ServiceUtils';
 import {
   type ChargingStation,
-  ChargingStationConfigurationUtils,
   checkChargingStation,
+  getConfigurationKey,
+  setConfigurationKeyValue,
 } from '../../../charging-station';
 import { OCPPError } from '../../../exception';
 import {
@@ -512,11 +513,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
       }
     } else if (isNotEmptyArray(commandPayload.key) === true) {
       for (const key of commandPayload.key!) {
-        const keyFound = ChargingStationConfigurationUtils.getConfigurationKey(
-          chargingStation,
-          key,
-          true,
-        );
+        const keyFound = getConfigurationKey(chargingStation, key, true);
         if (keyFound) {
           if (isUndefined(keyFound.visible) === true) {
             keyFound.visible = true;
@@ -544,22 +541,13 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
     chargingStation: ChargingStation,
     commandPayload: ChangeConfigurationRequest,
   ): ChangeConfigurationResponse {
-    const keyToChange = ChargingStationConfigurationUtils.getConfigurationKey(
-      chargingStation,
-      commandPayload.key,
-      true,
-    );
+    const keyToChange = getConfigurationKey(chargingStation, commandPayload.key, true);
     if (keyToChange?.readonly === true) {
       return OCPP16Constants.OCPP_CONFIGURATION_RESPONSE_REJECTED;
     } else if (keyToChange?.readonly === false) {
       let valueChanged = false;
       if (keyToChange.value !== commandPayload.value) {
-        ChargingStationConfigurationUtils.setConfigurationKeyValue(
-          chargingStation,
-          commandPayload.key,
-          commandPayload.value,
-          true,
-        );
+        setConfigurationKeyValue(chargingStation, commandPayload.key, commandPayload.value, true);
         valueChanged = true;
       }
       let triggerHeartbeatRestart = false;
@@ -568,7 +556,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
           OCPP16StandardParametersKey.HeartBeatInterval &&
         valueChanged
       ) {
-        ChargingStationConfigurationUtils.setConfigurationKeyValue(
+        setConfigurationKeyValue(
           chargingStation,
           OCPP16StandardParametersKey.HeartbeatInterval,
           commandPayload.value,
@@ -580,7 +568,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
           OCPP16StandardParametersKey.HeartbeatInterval &&
         valueChanged
       ) {
-        ChargingStationConfigurationUtils.setConfigurationKeyValue(
+        setConfigurationKeyValue(
           chargingStation,
           OCPP16StandardParametersKey.HeartBeatInterval,
           commandPayload.value,
index 02c03140e341654ddb8a2c4949cebb1d6d59fa39..78c2cedb8eb0f03e86daae5be1709c252a98f984 100644 (file)
@@ -7,7 +7,8 @@ import type { JSONSchemaType } from 'ajv';
 import { OCPP16ServiceUtils } from './OCPP16ServiceUtils';
 import {
   type ChargingStation,
-  ChargingStationConfigurationUtils,
+  addConfigurationKey,
+  getConfigurationKey,
   resetConnectorStatus,
 } from '../../../charging-station';
 import { OCPPError } from '../../../exception';
@@ -407,14 +408,14 @@ export class OCPP16ResponseService extends OCPPResponseService {
     payload: OCPP16BootNotificationResponse,
   ): void {
     if (payload.status === RegistrationStatusEnumType.ACCEPTED) {
-      ChargingStationConfigurationUtils.addConfigurationKey(
+      addConfigurationKey(
         chargingStation,
         OCPP16StandardParametersKey.HeartbeatInterval,
         payload.interval.toString(),
         {},
         { overwrite: true, save: true },
       );
-      ChargingStationConfigurationUtils.addConfigurationKey(
+      addConfigurationKey(
         chargingStation,
         OCPP16StandardParametersKey.HeartBeatInterval,
         payload.interval.toString(),
@@ -655,11 +656,10 @@ export class OCPP16ResponseService extends OCPPResponseService {
       if (chargingStation.stationInfo.powerSharedByConnectors) {
         ++chargingStation.powerDivider;
       }
-      const configuredMeterValueSampleInterval =
-        ChargingStationConfigurationUtils.getConfigurationKey(
-          chargingStation,
-          OCPP16StandardParametersKey.MeterValueSampleInterval,
-        );
+      const configuredMeterValueSampleInterval = getConfigurationKey(
+        chargingStation,
+        OCPP16StandardParametersKey.MeterValueSampleInterval,
+      );
       chargingStation.startMeterValues(
         transactionConnectorId,
         configuredMeterValueSampleInterval
index 4727194659aaad501a1f06e127eae9530f0278ee..81dca3a4a29a46de3c54d85ad3b3b2324ccccaf6 100644 (file)
@@ -3,7 +3,7 @@
 import type { JSONSchemaType } from 'ajv';
 
 import { OCPP20ServiceUtils } from './OCPP20ServiceUtils';
-import { type ChargingStation, ChargingStationConfigurationUtils } from '../../../charging-station';
+import { type ChargingStation, addConfigurationKey } from '../../../charging-station';
 import { OCPPError } from '../../../exception';
 import {
   ErrorType,
@@ -168,7 +168,7 @@ export class OCPP20ResponseService extends OCPPResponseService {
     payload: OCPP20BootNotificationResponse,
   ): void {
     if (payload.status === RegistrationStatusEnumType.ACCEPTED) {
-      ChargingStationConfigurationUtils.addConfigurationKey(
+      addConfigurationKey(
         chargingStation,
         OCPP20OptionalVariableName.HeartbeatInterval,
         payload.interval.toString(),
index 16d83ee99c6be12b4bc56cadc6e65d83830cbd03..5dbe2fb4953d66ab535141e0ac4de12362f2af74 100644 (file)
@@ -7,7 +7,7 @@ import type { DefinedError, ErrorObject, JSONSchemaType } from 'ajv';
 import { OCPP16Constants } from './1.6/OCPP16Constants';
 import { OCPP20Constants } from './2.0/OCPP20Constants';
 import { OCPPConstants } from './OCPPConstants';
-import { type ChargingStation, ChargingStationConfigurationUtils } from '../../charging-station';
+import { type ChargingStation, getConfigurationKey } from '../../charging-station';
 import { BaseError } from '../../exception';
 import {
   ChargePointErrorCode,
@@ -308,7 +308,7 @@ export class OCPPServiceUtils {
     }
     if (
       measurand !== MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER &&
-      ChargingStationConfigurationUtils.getConfigurationKey(
+      getConfigurationKey(
         chargingStation,
         StandardParametersKey.MeterValuesSampledData,
       )?.value?.includes(measurand) === false
@@ -340,7 +340,7 @@ export class OCPPServiceUtils {
         phase &&
         sampledValueTemplates[index]?.phase === phase &&
         sampledValueTemplates[index]?.measurand === measurand &&
-        ChargingStationConfigurationUtils.getConfigurationKey(
+        getConfigurationKey(
           chargingStation,
           StandardParametersKey.MeterValuesSampledData,
         )?.value?.includes(measurand) === true
@@ -350,7 +350,7 @@ export class OCPPServiceUtils {
         !phase &&
         !sampledValueTemplates[index].phase &&
         sampledValueTemplates[index]?.measurand === measurand &&
-        ChargingStationConfigurationUtils.getConfigurationKey(
+        getConfigurationKey(
           chargingStation,
           StandardParametersKey.MeterValuesSampledData,
         )?.value?.includes(measurand) === true