fix: add getter/setter on some station info attributes
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 23 Nov 2023 18:08:41 +0000 (19:08 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Thu, 23 Nov 2023 18:08:41 +0000 (19:08 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts

index 508567f37e7999a97fc3ad20564b2c37b1e6ae77..04c49c9279ebb44b1b4aed495cc181b08d2e247f 100644 (file)
@@ -226,7 +226,7 @@ export class ChargingStation extends EventEmitter {
   }
 
   public get stationInfo(): ChargingStationInfo {
-    return {
+    const stationInfo = {
       ...{
         enableStatistics: false,
         remoteAuthorization: true,
@@ -252,6 +252,31 @@ export class ChargingStation extends EventEmitter {
       },
       ...this.internalStationInfo,
     };
+    Object.defineProperty(stationInfo, 'supervisionUrls', {
+      set: (supervisionUrls: string | string[]) => {
+        this.internalStationInfo.supervisionUrls = supervisionUrls;
+      },
+      get: () => {
+        return this.internalStationInfo.supervisionUrls;
+      },
+    });
+    Object.defineProperty(stationInfo, 'firmwareVersion', {
+      set: (firmwareVersion: string) => {
+        this.internalStationInfo.firmwareVersion = firmwareVersion;
+      },
+      get: () => {
+        return this.internalStationInfo.firmwareVersion;
+      },
+    });
+    Object.defineProperty(stationInfo, 'firmwareStatus', {
+      set: (firmwareStatus: FirmwareStatus) => {
+        this.internalStationInfo.firmwareStatus = firmwareStatus;
+      },
+      get: () => {
+        return this.internalStationInfo.firmwareStatus;
+      },
+    });
+    return stationInfo;
   }
 
   private get wsConnectionUrl(): URL {
@@ -1172,7 +1197,7 @@ export class ChargingStation extends EventEmitter {
     return stationInfo;
   }
 
-  private getStationInfo(): ChargingStationInfo {
+  private getInternalStationInfo(): ChargingStationInfo {
     const stationInfoFromTemplate: ChargingStationInfo = this.getStationInfoFromTemplate();
     const stationInfoFromFile: ChargingStationInfo | undefined = this.getStationInfoFromFile();
     // Priority:
@@ -1219,7 +1244,7 @@ export class ChargingStation extends EventEmitter {
     } else {
       this.initializeConnectorsOrEvsesFromTemplate(stationTemplate);
     }
-    this.internalStationInfo = this.getStationInfo();
+    this.internalStationInfo = this.getInternalStationInfo();
     if (
       this.stationInfo.firmwareStatus === FirmwareStatus.Installing &&
       isNotEmptyString(this.stationInfo.firmwareVersion) &&
@@ -1732,7 +1757,7 @@ export class ChargingStation extends EventEmitter {
 
   private getOcppConfigurationFromFile(): ChargingStationOcppConfiguration | undefined {
     const configurationKey = this.getConfigurationFromFile()?.configurationKey;
-    if (this.stationInfo?.ocppPersistentConfiguration === true && configurationKey) {
+    if (this.stationInfo?.ocppPersistentConfiguration === true && Array.isArray(configurationKey)) {
       return { configurationKey };
     }
     return undefined;
@@ -2140,7 +2165,7 @@ export class ChargingStation extends EventEmitter {
         }
       }
     }
-    if (this.stationInfo?.firmwareStatus === FirmwareStatus.Installing) {
+    if (this.stationInfo.firmwareStatus === FirmwareStatus.Installing) {
       await this.ocppRequestService.requestHandler<
         FirmwareStatusNotificationRequest,
         FirmwareStatusNotificationResponse
index 2b34342e105ec2264f5f076d2a20062ca06910e4..3647ebdb78d9a234ac7a4a95673dc1a19cc18165 100644 (file)
@@ -1103,10 +1103,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
       return OCPP16Constants.OCPP_RESPONSE_EMPTY;
     }
     let { retrieveDate } = commandPayload;
-    if (
-      !isNullOrUndefined(chargingStation.stationInfo.firmwareStatus) &&
-      chargingStation.stationInfo.firmwareStatus !== OCPP16FirmwareStatus.Installed
-    ) {
+    if (chargingStation.stationInfo.firmwareStatus !== OCPP16FirmwareStatus.Installed) {
       logger.warn(
         `${chargingStation.logPrefix()} ${moduleName}.handleRequestUpdateFirmware: Cannot simulate firmware update: firmware update is already in progress`,
       );