From: Jérôme Benoit Date: Sat, 21 Aug 2021 12:26:23 +0000 (+0200) Subject: Fix sonarcloud bugs report. X-Git-Tag: v1.0.39~2 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=2891f7616d9f39d05f5c47876e29d2dbdbe9f6a5;p=e-mobility-charging-stations-simulator.git Fix sonarcloud bugs report. Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index de675622..666d3af3 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -940,8 +940,8 @@ export default class ChargingStation { } private openWSConnection(options?: ClientOptions & ClientRequestArgs, forceCloseOpened = false): void { - options ?? {}; - options?.handshakeTimeout ?? this.getConnectionTimeout() * 1000; + options = options ?? {}; + options.handshakeTimeout = options?.handshakeTimeout ?? this.getConnectionTimeout() * 1000; if (!Utils.isNullOrUndefined(this.stationInfo.supervisionUser) && !Utils.isNullOrUndefined(this.stationInfo.supervisionPassword)) { options.auth = `${this.stationInfo.supervisionUser}:${this.stationInfo.supervisionPassword}`; } diff --git a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts index ece3c286..1f19e858 100644 --- a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts @@ -382,7 +382,7 @@ export default class OCPP16RequestService extends OCPPRequestService { public async sendError(messageId: string, error: OCPPError, commandName: OCPP16RequestCommand | OCPP16IncomingRequestCommand): Promise { try { // Send error - return this.sendMessage(messageId, error, MessageType.CALL_ERROR_MESSAGE, commandName); + return await this.sendMessage(messageId, error, MessageType.CALL_ERROR_MESSAGE, commandName); } catch (err) { this.handleRequestError(commandName as OCPP16RequestCommand, err); } diff --git a/src/utils/PerformanceStatistics.ts b/src/utils/PerformanceStatistics.ts index 622a809e..8c536f85 100644 --- a/src/utils/PerformanceStatistics.ts +++ b/src/utils/PerformanceStatistics.ts @@ -117,7 +117,7 @@ export default class PerformanceStatistics { if (Array.isArray(dataSet) && dataSet.length === 1) { return dataSet[0]; } - const sortedDataSet = dataSet.slice().sort(); + const sortedDataSet = dataSet.slice().sort((a, b) => (a - b)); const middleIndex = Math.floor(sortedDataSet.length / 2); if (sortedDataSet.length % 2) { return sortedDataSet[middleIndex / 2]; @@ -133,7 +133,7 @@ export default class PerformanceStatistics { if (Utils.isEmptyArray(dataSet)) { return 0; } - const sortedDataSet = dataSet.slice().sort(); + const sortedDataSet = dataSet.slice().sort((a, b) => (a - b)); if (percentile === 0) { return sortedDataSet[0]; }