From 157482609a14720b298b9efde2b11f807824bb7d Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 12 Jan 2023 11:14:02 +0100 Subject: [PATCH] Properly build once the firmwareUpgrade default values MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStation.ts | 19 ++++++++----------- .../ocpp/1.6/OCPP16IncomingRequestService.ts | 8 ++++---- src/types/ChargingStationTemplate.ts | 2 +- 3 files changed, 13 insertions(+), 16 deletions(-) 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; }; -- 2.34.1