fix: make stationInfo attributes writable again
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 23 Nov 2023 19:40:10 +0000 (20:40 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Thu, 23 Nov 2023 19:40:10 +0000 (20:40 +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 04c49c9279ebb44b1b4aed495cc181b08d2e247f..3e1917a134eea9f9c5a757c725a4fd53ef09eee5 100644 (file)
@@ -158,6 +158,7 @@ import {
 export class ChargingStation extends EventEmitter {
   public readonly index: number;
   public readonly templateFile: string;
+  public stationInfo!: ChargingStationInfo;
   public started: boolean;
   public starting: boolean;
   public idTagsCache: IdTagsCache;
@@ -173,7 +174,6 @@ export class ChargingStation extends EventEmitter {
   public bootNotificationRequest!: BootNotificationRequest;
   public bootNotificationResponse!: BootNotificationResponse | undefined;
   public powerDivider!: number;
-  private internalStationInfo!: ChargingStationInfo;
   private stopping: boolean;
   private configurationFile!: string;
   private configurationFileHash!: string;
@@ -225,60 +225,6 @@ export class ChargingStation extends EventEmitter {
     return this.connectors.size === 0 && this.evses.size > 0;
   }
 
-  public get stationInfo(): ChargingStationInfo {
-    const stationInfo = {
-      ...{
-        enableStatistics: false,
-        remoteAuthorization: true,
-        currentOutType: CurrentType.AC,
-        mainVoltageMeterValues: true,
-        phaseLineToLineVoltageMeterValues: false,
-        customValueLimitationMeterValues: true,
-        ocppStrictCompliance: true,
-        outOfOrderEndMeterValues: false,
-        beginEndMeterValues: false,
-        meteringPerTransaction: true,
-        transactionDataMeterValues: false,
-        supervisionUrlOcppConfiguration: false,
-        supervisionUrlOcppKey: VendorParametersKey.ConnectionUrl,
-        ocppVersion: OCPPVersion.VERSION_16,
-        ocppPersistentConfiguration: true,
-        stationInfoPersistentConfiguration: true,
-        automaticTransactionGeneratorPersistentConfiguration: true,
-        autoReconnectMaxRetries: -1,
-        registrationMaxRetries: -1,
-        reconnectExponentialDelay: false,
-        stopTransactionsOnStopped: true,
-      },
-      ...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 {
     return new URL(
       `${
@@ -1197,14 +1143,37 @@ export class ChargingStation extends EventEmitter {
     return stationInfo;
   }
 
-  private getInternalStationInfo(): ChargingStationInfo {
+  private getStationInfo(): ChargingStationInfo {
+    const defaultStationInfo: Partial<ChargingStationInfo> = {
+      enableStatistics: false,
+      remoteAuthorization: true,
+      currentOutType: CurrentType.AC,
+      mainVoltageMeterValues: true,
+      phaseLineToLineVoltageMeterValues: false,
+      customValueLimitationMeterValues: true,
+      ocppStrictCompliance: true,
+      outOfOrderEndMeterValues: false,
+      beginEndMeterValues: false,
+      meteringPerTransaction: true,
+      transactionDataMeterValues: false,
+      supervisionUrlOcppConfiguration: false,
+      supervisionUrlOcppKey: VendorParametersKey.ConnectionUrl,
+      ocppVersion: OCPPVersion.VERSION_16,
+      ocppPersistentConfiguration: true,
+      stationInfoPersistentConfiguration: true,
+      automaticTransactionGeneratorPersistentConfiguration: true,
+      autoReconnectMaxRetries: -1,
+      registrationMaxRetries: -1,
+      reconnectExponentialDelay: false,
+      stopTransactionsOnStopped: true,
+    };
     const stationInfoFromTemplate: ChargingStationInfo = this.getStationInfoFromTemplate();
     const stationInfoFromFile: ChargingStationInfo | undefined = this.getStationInfoFromFile();
     // Priority:
     // 1. charging station info from template
     // 2. charging station info from configuration file
     if (stationInfoFromFile?.templateHash === stationInfoFromTemplate.templateHash) {
-      return stationInfoFromFile!;
+      return { ...defaultStationInfo, ...stationInfoFromFile! };
     }
     stationInfoFromFile &&
       propagateSerialNumber(
@@ -1212,7 +1181,7 @@ export class ChargingStation extends EventEmitter {
         stationInfoFromFile,
         stationInfoFromTemplate,
       );
-    return stationInfoFromTemplate;
+    return { ...defaultStationInfo, ...stationInfoFromTemplate };
   }
 
   private saveStationInfo(): void {
@@ -1244,7 +1213,7 @@ export class ChargingStation extends EventEmitter {
     } else {
       this.initializeConnectorsOrEvsesFromTemplate(stationTemplate);
     }
-    this.internalStationInfo = this.getInternalStationInfo();
+    this.stationInfo = this.getStationInfo();
     if (
       this.stationInfo.firmwareStatus === FirmwareStatus.Installing &&
       isNotEmptyString(this.stationInfo.firmwareVersion) &&
index 3647ebdb78d9a234ac7a4a95673dc1a19cc18165..2b34342e105ec2264f5f076d2a20062ca06910e4 100644 (file)
@@ -1103,7 +1103,10 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
       return OCPP16Constants.OCPP_RESPONSE_EMPTY;
     }
     let { retrieveDate } = commandPayload;
-    if (chargingStation.stationInfo.firmwareStatus !== OCPP16FirmwareStatus.Installed) {
+    if (
+      !isNullOrUndefined(chargingStation.stationInfo.firmwareStatus) &&
+      chargingStation.stationInfo.firmwareStatus !== OCPP16FirmwareStatus.Installed
+    ) {
       logger.warn(
         `${chargingStation.logPrefix()} ${moduleName}.handleRequestUpdateFirmware: Cannot simulate firmware update: firmware update is already in progress`,
       );