Fix sonarcloud bugs report.
authorJérôme Benoit <jerome.benoit@sap.com>
Sat, 21 Aug 2021 12:26:23 +0000 (14:26 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sat, 21 Aug 2021 12:26:23 +0000 (14:26 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/ocpp/1.6/OCPP16RequestService.ts
src/utils/PerformanceStatistics.ts

index de6756228b1f47d6604389fd8f3e839636b8c4d2..666d3af356e5d00a9e900ffc098fb5079332f34a 100644 (file)
@@ -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}`;
     }
index ece3c2866e5a5f2990a560d8a5a4514f65ce7e2d..1f19e858717b097990ceca04f9d3d9a7e73756fc 100644 (file)
@@ -382,7 +382,7 @@ export default class OCPP16RequestService extends OCPPRequestService {
   public async sendError(messageId: string, error: OCPPError, commandName: OCPP16RequestCommand | OCPP16IncomingRequestCommand): Promise<unknown> {
     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);
     }
index 622a809e2ab428f60824e529121c5b8975b9b4bd..8c536f85a669bd8b39f02b801884401631191d6d 100644 (file)
@@ -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];
     }