From f832e5df7441f4478d612443098b8feb71277c5f Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 29 Apr 2023 01:24:21 +0200 Subject: [PATCH] fix: fix station info generation 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 | 21 ++++++------- src/charging-station/ChargingStationUtils.ts | 31 +++++--------------- src/types/ChargingStationInfo.ts | 1 + ui/web/src/types/ChargingStationType.ts | 1 - 4 files changed, 17 insertions(+), 37 deletions(-) diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 5d400371..b27f5b2e 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -993,18 +993,22 @@ export class ChargingStation { stationInfo.resetTime = !Utils.isNullOrUndefined(stationTemplate?.resetTime) ? stationTemplate.resetTime * 1000 : Constants.CHARGING_STATION_DEFAULT_RESET_TIME; - // Initialize evses or connectors if needed (FIXME: should be factored out) + // Initialize evses or connectors if needed (FIXME: should be factored out but connectors and evses configuration are only available in templates) this.initializeConnectorsOrEvses(stationInfo); stationInfo.maximumAmperage = this.getMaximumAmperage(stationInfo); - ChargingStationUtils.createStationInfoHash(stationInfo); + delete stationInfo?.Connectors; + delete stationInfo?.Evses; return stationInfo; } private getStationInfoFromFile(): ChargingStationInfo | undefined { let stationInfo: ChargingStationInfo | undefined; - this.getStationInfoPersistentConfiguration() && - (stationInfo = this.getConfigurationFromFile()?.stationInfo); - stationInfo && ChargingStationUtils.createStationInfoHash(stationInfo); + if (this.getStationInfoPersistentConfiguration()) { + stationInfo = this.getConfigurationFromFile()?.stationInfo; + if (stationInfo) { + delete stationInfo?.infoHash; + } + } return stationInfo; } @@ -1014,11 +1018,7 @@ export class ChargingStation { // Priority: // 1. charging station info from template // 2. charging station info from configuration file - // 3. charging station info attribute if (stationInfoFromFile?.templateHash === stationInfoFromTemplate.templateHash) { - if (this.stationInfo?.infoHash === stationInfoFromFile?.infoHash) { - return this.stationInfo; - } return stationInfoFromFile; } stationInfoFromFile && @@ -1075,9 +1075,6 @@ export class ChargingStation { this.stationInfo.firmwareVersion = match?.join('.'); } this.saveStationInfo(); - // Avoid duplication of connectors or evses related information in RAM - delete this.stationInfo?.Connectors; - delete this.stationInfo?.Evses; this.configuredSupervisionUrl = this.getConfiguredSupervisionUrl(); if (this.getEnableStatistics() === true) { this.performanceStatistics = PerformanceStatistics.getInstance( diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index c58db0ce..cac243ff 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -387,14 +387,6 @@ export class ChargingStationUtils { return stationTemplate as unknown as ChargingStationInfo; } - public static createStationInfoHash(stationInfo: ChargingStationInfo): void { - delete stationInfo.infoHash; - stationInfo.infoHash = crypto - .createHash(Constants.DEFAULT_HASH_ALGORITHM) - .update(JSON.stringify(stationInfo)) - .digest('hex'); - } - public static createSerialNumber( stationTemplate: ChargingStationTemplate, stationInfo: ChargingStationInfo, @@ -406,27 +398,18 @@ export class ChargingStationUtils { randomSerialNumber: true, } ): void { - params = params ?? {}; - params.randomSerialNumberUpperCase = params?.randomSerialNumberUpperCase ?? true; - params.randomSerialNumber = params?.randomSerialNumber ?? true; + params = { ...{ randomSerialNumberUpperCase: true, randomSerialNumber: true }, ...params }; const serialNumberSuffix = params?.randomSerialNumber ? ChargingStationUtils.getRandomSerialNumberSuffix({ upperCase: params.randomSerialNumberUpperCase, }) : ''; - stationInfo.chargePointSerialNumber = Utils.isNotEmptyString( - stationTemplate?.chargePointSerialNumberPrefix - ) - ? `${stationTemplate.chargePointSerialNumberPrefix}${serialNumberSuffix}` - : undefined; - stationInfo.chargeBoxSerialNumber = Utils.isNotEmptyString( - stationTemplate?.chargeBoxSerialNumberPrefix - ) - ? `${stationTemplate.chargeBoxSerialNumberPrefix}${serialNumberSuffix}` - : undefined; - stationInfo.meterSerialNumber = Utils.isNotEmptyString(stationTemplate?.meterSerialNumberPrefix) - ? `${stationTemplate.meterSerialNumberPrefix}${serialNumberSuffix}` - : undefined; + Utils.isNotEmptyString(stationTemplate?.chargePointSerialNumberPrefix) && + (stationInfo.chargePointSerialNumber = `${stationTemplate.chargePointSerialNumberPrefix}${serialNumberSuffix}`); + Utils.isNotEmptyString(stationTemplate?.chargeBoxSerialNumberPrefix) && + (stationInfo.chargeBoxSerialNumber = `${stationTemplate.chargeBoxSerialNumberPrefix}${serialNumberSuffix}`); + Utils.isNotEmptyString(stationTemplate?.meterSerialNumberPrefix) && + (stationInfo.meterSerialNumber = `${stationTemplate.meterSerialNumberPrefix}${serialNumberSuffix}`); } public static propagateSerialNumber( diff --git a/src/types/ChargingStationInfo.ts b/src/types/ChargingStationInfo.ts index 4f533623..1d91b375 100644 --- a/src/types/ChargingStationInfo.ts +++ b/src/types/ChargingStationInfo.ts @@ -20,6 +20,7 @@ export type ChargingStationInfo = Omit< | 'meterSerialNumberPrefix' > & { hashId: string; + /** @deprecated Use hashId instead */ infoHash?: string; chargingStationId?: string; chargeBoxSerialNumber?: string; diff --git a/ui/web/src/types/ChargingStationType.ts b/ui/web/src/types/ChargingStationType.ts index e9f5f108..b391bef5 100644 --- a/ui/web/src/types/ChargingStationType.ts +++ b/ui/web/src/types/ChargingStationType.ts @@ -23,7 +23,6 @@ export type ChargingStationInfo = { firmwareVersion?: string; numberOfConnectors?: number | number[]; baseName: string; - infoHash?: string; templateHash?: string; chargeBoxSerialNumber?: string; chargePointSerialNumber?: string; -- 2.34.1