From: Jérôme Benoit Date: Sun, 30 Apr 2023 18:24:38 +0000 (+0200) Subject: fix: reference a connector status clone in connectors map X-Git-Tag: v1.2.12~35 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=8df5ae48c46a80c5a9518132c3a1a5cff3473597;p=e-mobility-charging-stations-simulator.git fix: reference a connector status clone in connectors map Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 56ce26a1..436d7b02 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -109,7 +109,7 @@ export class ChargingStation { public automaticTransactionGenerator!: AutomaticTransactionGenerator | undefined; public ocppConfiguration!: ChargingStationOcppConfiguration | undefined; public wsConnection!: WebSocket | null; - public connectors: Map; + public readonly connectors: Map; public readonly evses: Map; public readonly requests: Map; public performanceStatistics!: PerformanceStatistics | undefined; @@ -1312,18 +1312,15 @@ export class ChargingStation { private initializeConnectorsOrEvsesFromFile(configuration: ChargingStationConfiguration): void { if (configuration?.connectorsStatus && !configuration?.evsesStatus) { - this.connectors = new Map( - configuration?.connectorsStatus.map((connectorStatus, connectorId) => [ - connectorId, - connectorStatus, - ]) - ); + for (const [connectorId, connectorStatus] of configuration.connectorsStatus.entries()) { + this.connectors.set(connectorId, Utils.cloneObject(connectorStatus)); + } } else if (configuration?.evsesStatus && !configuration?.connectorsStatus) { for (const [evseId, evseStatusConfiguration] of configuration.evsesStatus.entries()) { - const evseStatus = Utils.cloneObject(evseStatusConfiguration); + const evseStatus = Utils.cloneObject(evseStatusConfiguration); delete evseStatus.connectorsStatus; this.evses.set(evseId, { - ...evseStatus, + ...(evseStatus as EvseStatus), connectors: new Map( evseStatusConfiguration.connectorsStatus.map((connectorStatus, connectorId) => [ connectorId, @@ -1557,7 +1554,7 @@ export class ChargingStation { fs.mkdirSync(path.dirname(this.configurationFile), { recursive: true }); } let configurationData: ChargingStationConfiguration = - Utils.cloneObject(this.getConfigurationFromFile()) ?? {}; + Utils.cloneObject(this.getConfigurationFromFile()) ?? {}; if (this.getStationInfoPersistentConfiguration() && this.stationInfo) { configurationData.stationInfo = this.stationInfo; } @@ -1632,20 +1629,9 @@ export class ChargingStation { } private getOcppConfigurationFromFile(): ChargingStationOcppConfiguration | undefined { - let configuration: ChargingStationConfiguration | undefined; if (this.getOcppPersistentConfiguration() === true) { - const configurationFromFile = this.getConfigurationFromFile(); - configuration = configurationFromFile?.configurationKey && configurationFromFile; - } - if (!Utils.isNullOrUndefined(configuration)) { - delete configuration.stationInfo; - delete configuration.connectorsStatus; - delete configuration.evsesStatus; - delete configuration.automaticTransactionGenerator; - delete configuration.automaticTransactionGeneratorStatuses; - delete configuration.configurationHash; + return { configurationKey: this.getConfigurationFromFile()?.configurationKey }; } - return configuration; } private getOcppConfiguration(): ChargingStationOcppConfiguration | undefined { diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index 4084a484..d8f67c21 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -389,7 +389,7 @@ export class ChargingStationUtils { public static stationTemplateToStationInfo( stationTemplate: ChargingStationTemplate ): ChargingStationInfo { - stationTemplate = Utils.cloneObject(stationTemplate); + stationTemplate = Utils.cloneObject(stationTemplate); delete stationTemplate.power; delete stationTemplate.powerUnit; delete stationTemplate?.Connectors; @@ -471,15 +471,15 @@ export class ChargingStationUtils { let limit: number, matchingChargingProfile: ChargingProfile; // Get charging profiles for connector and sort by stack level const chargingProfiles = - Utils.cloneObject(chargingStation.getConnectorStatus(connectorId)?.chargingProfiles)?.sort( - (a, b) => b.stackLevel - a.stackLevel - ) ?? []; + Utils.cloneObject( + chargingStation.getConnectorStatus(connectorId)?.chargingProfiles + )?.sort((a, b) => b.stackLevel - a.stackLevel) ?? []; // Get profiles on connector 0 if (chargingStation.getConnectorStatus(0)?.chargingProfiles) { chargingProfiles.push( - ...Utils.cloneObject(chargingStation.getConnectorStatus(0).chargingProfiles).sort( - (a, b) => b.stackLevel - a.stackLevel - ) + ...Utils.cloneObject( + chargingStation.getConnectorStatus(0).chargingProfiles + ).sort((a, b) => b.stackLevel - a.stackLevel) ); } if (Utils.isNotEmptyArray(chargingProfiles)) {