refactor: cleanup default optional default arguments handling
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 4 Aug 2023 13:55:49 +0000 (15:55 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 4 Aug 2023 13:55:49 +0000 (15:55 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/ConfigurationKeyUtils.ts
src/charging-station/Helpers.ts
src/charging-station/ocpp/OCPPRequestService.ts
src/charging-station/ocpp/OCPPServiceUtils.ts

index 6adbd74d2e20fb90331222be6f884a4ce942048a..5a049ec5b9195b071f4920f117a6ea4e4ca59a02 100644 (file)
@@ -771,13 +771,14 @@ export class ChargingStation {
   }
 
   public openWSConnection(
-    options: WsOptions = this.stationInfo?.wsOptions ?? {},
-    params: { closeOpened?: boolean; terminateOpened?: boolean } = {
-      closeOpened: false,
-      terminateOpened: false,
-    },
+    options?: WsOptions,
+    params?: { closeOpened?: boolean; terminateOpened?: boolean },
   ): void {
-    options = { handshakeTimeout: secondsToMilliseconds(this.getConnectionTimeout()), ...options };
+    options = {
+      handshakeTimeout: secondsToMilliseconds(this.getConnectionTimeout()),
+      ...(this.stationInfo?.wsOptions ?? {}),
+      ...options,
+    };
     params = { ...{ closeOpened: false, terminateOpened: false }, ...params };
     if (this.started === false && this.starting === false) {
       logger.warn(
@@ -2367,7 +2368,6 @@ export class ChargingStation {
       );
       this.openWSConnection(
         {
-          ...(this.stationInfo?.wsOptions ?? {}),
           handshakeTimeout: reconnectTimeout,
         },
         { closeOpened: true },
index 39606b66e1ea8d08cacc61b53d58607d53d9c73d..96a13e71d44f3f2da4c92b50e151d6a96d50c189 100644 (file)
@@ -33,12 +33,8 @@ export const addConfigurationKey = (
   chargingStation: ChargingStation,
   key: ConfigurationKeyType,
   value: string,
-  options: ConfigurationKeyOptions = {
-    readonly: false,
-    visible: true,
-    reboot: false,
-  },
-  params: AddConfigurationKeyParams = { overwrite: false, save: false },
+  options?: ConfigurationKeyOptions,
+  params?: AddConfigurationKeyParams,
 ): void => {
   options = {
     ...{
@@ -96,7 +92,7 @@ export const setConfigurationKeyValue = (
 export const deleteConfigurationKey = (
   chargingStation: ChargingStation,
   key: ConfigurationKeyType,
-  params: DeleteConfigurationKeyParams = { save: true, caseInsensitive: false },
+  params?: DeleteConfigurationKeyParams,
 ): ConfigurationKey[] | undefined => {
   params = { ...{ save: true, caseInsensitive: false }, ...params };
   const keyFound = getConfigurationKey(chargingStation, key, params?.caseInsensitive);
index 936c1a7d65a9136dbd11843c915f91a8d334f0b6..bb3bb5af51d540396337e41ef3194cf703d4932d 100644 (file)
@@ -452,12 +452,9 @@ export const stationTemplateToStationInfo = (
 export const createSerialNumber = (
   stationTemplate: ChargingStationTemplate,
   stationInfo: ChargingStationInfo,
-  params: {
+  params?: {
     randomSerialNumberUpperCase?: boolean;
     randomSerialNumber?: boolean;
-  } = {
-    randomSerialNumberUpperCase: true,
-    randomSerialNumber: true,
   },
 ): void => {
   params = { ...{ randomSerialNumberUpperCase: true, randomSerialNumber: true }, ...params };
index 4e456963798a6f121b1bd89594dd956f59c49bce..ccab6468353d32e58eaf5a2317d63848ca18aee0 100644 (file)
@@ -173,7 +173,7 @@ export abstract class OCPPRequestService {
     messageId: string,
     messagePayload: JsonType,
     commandName: RequestCommand,
-    params: RequestParams = defaultRequestParams,
+    params?: RequestParams,
   ): Promise<ResponseType> {
     params = {
       ...defaultRequestParams,
@@ -276,7 +276,7 @@ export abstract class OCPPRequestService {
     messagePayload: JsonType | OCPPError,
     messageType: MessageType,
     commandName: RequestCommand | IncomingRequestCommand,
-    params: RequestParams = defaultRequestParams,
+    params?: RequestParams,
   ): Promise<ResponseType> {
     params = {
       ...defaultRequestParams,
@@ -388,7 +388,7 @@ export abstract class OCPPRequestService {
             PerformanceStatistics.endMeasure(commandName, beginId);
           }
           const wsClosedOrErrored = !wsOpened || sendError === true;
-          if (wsClosedOrErrored && params.skipBufferingOnError === false) {
+          if (wsClosedOrErrored && params?.skipBufferingOnError === false) {
             // Buffer
             chargingStation.bufferMessage(messageToSend);
             // Reject and keep request in the cache
index f5bbe1602290dbba4699600570c46a76a10c44f4..d3930db4244b11502ccea147df11e641af5b5d0b 100644 (file)
@@ -406,10 +406,7 @@ export class OCPPServiceUtils {
   protected static getLimitFromSampledValueTemplateCustomValue(
     value: string,
     limit: number,
-    options: { limitationEnabled?: boolean; unitMultiplier?: number } = {
-      limitationEnabled: true,
-      unitMultiplier: 1,
-    },
+    options?: { limitationEnabled?: boolean; unitMultiplier?: number },
   ): number {
     options = {
       ...{