From: Jérôme Benoit Date: Fri, 4 Aug 2023 13:55:49 +0000 (+0200) Subject: refactor: cleanup default optional default arguments handling X-Git-Tag: v1.2.20~18 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=7f3decca34321ef6f6bf3b7f40a50db75dae1eed;p=e-mobility-charging-stations-simulator.git refactor: cleanup default optional default arguments handling Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 6adbd74d..5a049ec5 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -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 }, diff --git a/src/charging-station/ConfigurationKeyUtils.ts b/src/charging-station/ConfigurationKeyUtils.ts index 39606b66..96a13e71 100644 --- a/src/charging-station/ConfigurationKeyUtils.ts +++ b/src/charging-station/ConfigurationKeyUtils.ts @@ -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); diff --git a/src/charging-station/Helpers.ts b/src/charging-station/Helpers.ts index 936c1a7d..bb3bb5af 100644 --- a/src/charging-station/Helpers.ts +++ b/src/charging-station/Helpers.ts @@ -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 }; diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index 4e456963..ccab6468 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -173,7 +173,7 @@ export abstract class OCPPRequestService { messageId: string, messagePayload: JsonType, commandName: RequestCommand, - params: RequestParams = defaultRequestParams, + params?: RequestParams, ): Promise { params = { ...defaultRequestParams, @@ -276,7 +276,7 @@ export abstract class OCPPRequestService { messagePayload: JsonType | OCPPError, messageType: MessageType, commandName: RequestCommand | IncomingRequestCommand, - params: RequestParams = defaultRequestParams, + params?: RequestParams, ): Promise { 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 diff --git a/src/charging-station/ocpp/OCPPServiceUtils.ts b/src/charging-station/ocpp/OCPPServiceUtils.ts index f5bbe160..d3930db4 100644 --- a/src/charging-station/ocpp/OCPPServiceUtils.ts +++ b/src/charging-station/ocpp/OCPPServiceUtils.ts @@ -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 = { ...{