From: Jérôme Benoit Date: Thu, 23 Nov 2023 18:08:41 +0000 (+0100) Subject: fix: add getter/setter on some station info attributes X-Git-Tag: v1.2.26~8 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=9fe79a139245f48ce0b6b05a90e601a749c37507;p=e-mobility-charging-stations-simulator.git fix: add getter/setter on some station info attributes Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 508567f3..04c49c92 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -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 diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 2b34342e..3647ebdb 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -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`, );