From: Jérôme Benoit Date: Thu, 12 Jan 2023 10:14:02 +0000 (+0100) Subject: Properly build once the firmwareUpgrade default values X-Git-Tag: v1.1.90~21 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=157482609a14720b298b9efde2b11f807824bb7d;p=e-mobility-charging-stations-simulator.git Properly build once the firmwareUpgrade default values Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index a7a41ddd..6f93e650 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -565,15 +565,6 @@ export default class ChargingStation { } } - public getFirmwareUpgrade(): FirmwareUpgrade { - return merge( - { - reset: true, - }, - this.stationInfo.firmwareUpgrade - ); - } - public async reset(reason?: StopTransactionReason): Promise { 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)) diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 6f089a70..3db474c7 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -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); } diff --git a/src/types/ChargingStationTemplate.ts b/src/types/ChargingStationTemplate.ts index 99b43765..5c44ede9 100644 --- a/src/types/ChargingStationTemplate.ts +++ b/src/types/ChargingStationTemplate.ts @@ -41,7 +41,7 @@ export enum Voltage { export type WsOptions = ClientOptions & ClientRequestArgs; export type FirmwareUpgrade = { - versionUpgrade: { + versionUpgrade?: { patternGroup?: number; step?: number; };