Properly build once the firmwareUpgrade default values
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 12 Jan 2023 10:14:02 +0000 (11:14 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Thu, 12 Jan 2023 10:14:02 +0000 (11:14 +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
src/types/ChargingStationTemplate.ts

index a7a41dddcbf6dbf30a4487c0f925e54dfc1f8b25..6f93e650585ecc287ff32b1f31e0408e9621d64e 100644 (file)
@@ -565,15 +565,6 @@ export default class ChargingStation {
     }
   }
 
-  public getFirmwareUpgrade(): FirmwareUpgrade {
-    return merge(
-      {
-        reset: true,
-      },
-      this.stationInfo.firmwareUpgrade
-    );
-  }
-
   public async reset(reason?: StopTransactionReason): Promise<void> {
     await this.stop(reason);
     await Utils.sleep(this.stationInfo.resetTime);
@@ -870,6 +861,12 @@ export default class ChargingStation {
         } does not match firmware version pattern '${stationInfo.firmwareVersionPattern}'`
       );
     }
+    stationInfo.firmwareUpgrade = merge(
+      {
+        reset: true,
+      },
+      stationTemplate.firmwareUpgrade ?? {}
+    );
     stationInfo.resetTime = stationTemplate.resetTime
       ? stationTemplate.resetTime * 1000
       : Constants.CHARGING_STATION_DEFAULT_RESET_TIME;
@@ -1013,9 +1010,9 @@ export default class ChargingStation {
       this.stationInfo.firmwareVersion &&
       this.stationInfo.firmwareVersionPattern
     ) {
-      const versionStep = this.getFirmwareUpgrade()?.versionUpgrade?.step ?? 1;
+      const versionStep = this.stationInfo.firmwareUpgrade?.versionUpgrade?.step ?? 1;
       const patternGroup: number =
-        this.getFirmwareUpgrade()?.versionUpgrade?.patternGroup ??
+        this.stationInfo.firmwareUpgrade?.versionUpgrade?.patternGroup ??
         this.stationInfo.firmwareVersion.split('.').length;
       const match = this.stationInfo.firmwareVersion
         .match(new RegExp(this.stationInfo.firmwareVersionPattern))
index 6f089a7029eb78cdcb0705276960a1db345ff0e2..3db474c75f827b7c53bff12cc22c74d90d2ccf0d 100644 (file)
@@ -1006,14 +1006,14 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
       }
     }
     if (
-      chargingStation.getFirmwareUpgrade()?.failureStatus &&
-      !Utils.isEmptyString(chargingStation.getFirmwareUpgrade().failureStatus)
+      chargingStation.stationInfo?.firmwareUpgrade?.failureStatus &&
+      !Utils.isEmptyString(chargingStation.stationInfo?.firmwareUpgrade?.failureStatus)
     ) {
       await chargingStation.ocppRequestService.requestHandler<
         OCPP16FirmwareStatusNotificationRequest,
         OCPP16FirmwareStatusNotificationResponse
       >(chargingStation, OCPP16RequestCommand.FIRMWARE_STATUS_NOTIFICATION, {
-        status: chargingStation.getFirmwareUpgrade().failureStatus,
+        status: chargingStation.stationInfo?.firmwareUpgrade?.failureStatus,
       });
       return;
     }
@@ -1040,7 +1040,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
       status: OCPP16FirmwareStatus.Installing,
     });
     chargingStation.stationInfo.firmwareStatus = OCPP16FirmwareStatus.Installing;
-    if (chargingStation.getFirmwareUpgrade().reset === true) {
+    if (chargingStation.stationInfo?.firmwareUpgrade?.reset === true) {
       await Utils.sleep(Utils.getRandomInteger(maxDelay, minDelay) * 1000);
       await chargingStation.reset(OCPP16StopTransactionReason.REBOOT);
     }
index 99b43765232fde1a66428745d7b411b5d0af89f7..5c44ede928435031caf6d445fdaf03a0f7602e62 100644 (file)
@@ -41,7 +41,7 @@ export enum Voltage {
 export type WsOptions = ClientOptions & ClientRequestArgs;
 
 export type FirmwareUpgrade = {
-  versionUpgrade: {
+  versionUpgrade?: {
     patternGroup?: number;
     step?: number;
   };