fix(simulator): fix brown paper bag bugs after helpers semantic fix
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 10 Feb 2023 21:10:40 +0000 (22:10 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 10 Feb 2023 21:10:40 +0000 (22:10 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStationUtils.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
src/performance/PerformanceStatistics.ts
src/types/ocpp/1.6/Requests.ts
src/utils/CircularArray.ts
src/utils/Constants.ts
test/utils/CircularArrayTest.ts

index 54e4df72d8f0105e050f005c5b062dc7ef31a817..9d23f1b4d7e6135f94f9205b57c03b8b6ed175c8 100644 (file)
@@ -268,15 +268,19 @@ export class ChargingStationUtils {
           upperCase: params.randomSerialNumberUpperCase,
         })
       : '';
-    stationInfo.chargePointSerialNumber =
-      Utils.isNotEmptyString(stationTemplate?.chargePointSerialNumberPrefix) &&
-      `${stationTemplate.chargePointSerialNumberPrefix}${serialNumberSuffix}`;
-    stationInfo.chargeBoxSerialNumber =
-      Utils.isNotEmptyString(stationTemplate?.chargeBoxSerialNumberPrefix) &&
-      `${stationTemplate.chargeBoxSerialNumberPrefix}${serialNumberSuffix}`;
-    stationInfo.meterSerialNumber =
-      Utils.isNotEmptyString(stationTemplate?.meterSerialNumberPrefix) &&
-      `${stationTemplate.meterSerialNumberPrefix}${serialNumberSuffix}`;
+    stationInfo.chargePointSerialNumber = Utils.isNotEmptyString(
+      stationTemplate?.chargePointSerialNumberPrefix
+    )
+      ? `${stationTemplate.chargePointSerialNumberPrefix}${serialNumberSuffix}`
+      : undefined;
+    stationInfo.chargeBoxSerialNumber = Utils.isNotEmptyString(
+      stationTemplate?.chargeBoxSerialNumberPrefix
+    )
+      ? `${stationTemplate.chargeBoxSerialNumberPrefix}${serialNumberSuffix}`
+      : undefined;
+    stationInfo.meterSerialNumber = Utils.isNotEmptyString(stationTemplate?.meterSerialNumberPrefix)
+      ? `${stationTemplate.meterSerialNumberPrefix}${serialNumberSuffix}`
+      : undefined;
   }
 
   public static propagateSerialNumber(
index 7fcb12fb0b79353d7b61ae02b6e6f21dcb867b60..3d5517dde9c8f33dbbea49e29020994427402383 100644 (file)
@@ -425,7 +425,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
   ): GetConfigurationResponse {
     const configurationKey: OCPPConfigurationKey[] = [];
     const unknownKey: string[] = [];
-    if (Utils.isEmptyArray(commandPayload.key) === true) {
+    if (Utils.isUndefined(commandPayload.key) === true) {
       for (const configuration of chargingStation.ocppConfiguration.configurationKey) {
         if (Utils.isUndefined(configuration.visible) === true) {
           configuration.visible = true;
@@ -439,7 +439,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
           value: configuration.value,
         });
       }
-    } else {
+    } else if (Utils.isNotEmptyArray(commandPayload.key) === true) {
       for (const key of commandPayload.key) {
         const keyFound = ChargingStationConfigurationUtils.getConfigurationKey(
           chargingStation,
index 1d3bb76ce6e3f5a2e57dc66726df943abf3b7266..aa0cc72325d903bf2de6ff0a8a44c8b959207f53 100644 (file)
@@ -8,8 +8,9 @@ import { MessageChannelUtils } from '../charging-station/MessageChannelUtils';
 import { MessageType } from '../types/ocpp/MessageType';
 import type { IncomingRequestCommand, RequestCommand } from '../types/ocpp/Requests';
 import type { Statistics, TimeSeries } from '../types/Statistics';
-import { CircularArray, DEFAULT_CIRCULAR_ARRAY_SIZE } from '../utils/CircularArray';
+import { CircularArray } from '../utils/CircularArray';
 import Configuration from '../utils/Configuration';
+import Constants from '../utils/Constants';
 import logger from '../utils/Logger';
 import Utils from '../utils/Utils';
 
@@ -253,12 +254,12 @@ export default class PerformanceStatistics {
     this.statistics.statisticsData.get(entryName).avgTimeMeasurement =
       this.statistics.statisticsData.get(entryName).totalTimeMeasurement /
       this.statistics.statisticsData.get(entryName).countTimeMeasurement;
-    Array.isArray(this.statistics.statisticsData.get(entryName)?.timeMeasurementSeries) === true
+    this.statistics.statisticsData.get(entryName)?.timeMeasurementSeries instanceof CircularArray
       ? this.statistics.statisticsData
           .get(entryName)
           ?.timeMeasurementSeries?.push({ timestamp: entry.startTime, value: entry.duration })
       : (this.statistics.statisticsData.get(entryName).timeMeasurementSeries =
-          new CircularArray<TimeSeries>(DEFAULT_CIRCULAR_ARRAY_SIZE, {
+          new CircularArray<TimeSeries>(Constants.DEFAULT_CIRCULAR_BUFFER_CAPACITY, {
             timestamp: entry.startTime,
             value: entry.duration,
           }));
index f8a1957009e70c77f5a3a2d9152ec0dc88756d8f..89316dc6b656459530cfefa5bf1409cd7f6f4e9a 100644 (file)
@@ -82,7 +82,7 @@ export interface UnlockConnectorRequest extends JsonObject {
 }
 
 export interface GetConfigurationRequest extends JsonObject {
-  key?: string | OCPP16StandardParametersKey[];
+  key?: (string | OCPP16StandardParametersKey)[];
 }
 
 export enum ResetType {
index 5fdeeaad1f7e57c2dae60d0c6fe976d623c942bd..ad25bf858b4197bc5c0789b478f89bba84b3ab6a 100644 (file)
@@ -1,6 +1,6 @@
 // Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
 
-export const DEFAULT_CIRCULAR_ARRAY_SIZE = Number.MAX_SAFE_INTEGER;
+const DEFAULT_CIRCULAR_ARRAY_SIZE = 1024;
 
 /**
  * Array with a maximum length shifting items when full.
index 241018fca18fff398590e56b1440ec6d3b260827..c6c691b05e49706fc58fa4cf334d31eb1450df63 100644 (file)
@@ -13,7 +13,7 @@ export default class Constants {
   static readonly SEMVER_PATTERN =
     '^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$';
 
-  static readonly DEFAULT_CIRCULAR_BUFFER_CAPACITY = Number.MAX_SAFE_INTEGER;
+  static readonly DEFAULT_CIRCULAR_BUFFER_CAPACITY = 1024;
 
   static readonly DEFAULT_HASH_ALGORITHM = 'sha384';
 
index c8b38a9a2a9cdccfe925f05d6f5d911ee7693cc3..1017452039a8b8bae3d49c6c5f2c9f605f54c080 100644 (file)
@@ -10,7 +10,7 @@ describe('Circular array test suite', () => {
 
   it('Verify circular array default size at instance creation', () => {
     const circularArray = new CircularArray();
-    expect(circularArray.size).toBe(Number.MAX_SAFE_INTEGER);
+    expect(circularArray.size).toBe(1024);
   });
 
   it('Verify that circular array size can be set at instance creation', () => {