From 2891f7616d9f39d05f5c47876e29d2dbdbe9f6a5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 21 Aug 2021 14:26:23 +0200 Subject: [PATCH] Fix sonarcloud bugs report. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStation.ts | 4 ++-- src/charging-station/ocpp/1.6/OCPP16RequestService.ts | 2 +- src/utils/PerformanceStatistics.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) 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]; } -- 2.34.1