From d21c49d6524dd8c4cb29da3d0925a5994ac6feb1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 26 Mar 2023 16:58:01 +0200 Subject: [PATCH] refactor(simulator): factor out template key deprecation handling 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 | 47 ++++++++++++------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 831c662e..43fb6889 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -854,6 +854,27 @@ export class ChargingStation { return template; } + private warnTemplateKeysDeprecation(stationTemplate: ChargingStationTemplate) { + const templateKeys: { key: string; deprecatedKey: string }[] = [ + { key: 'supervisionUrls', deprecatedKey: 'supervisionUrl' }, + { key: 'idTagsFile', deprecatedKey: 'authorizationFile' }, + ]; + for (const templateKey of templateKeys) { + ChargingStationUtils.warnDeprecatedTemplateKey( + stationTemplate, + templateKey.deprecatedKey, + this.templateFile, + this.logPrefix(), + `Use '${templateKey.key}' instead` + ); + ChargingStationUtils.convertDeprecatedTemplateKey( + stationTemplate, + templateKey.deprecatedKey, + templateKey.key + ); + } + } + private getStationInfoFromTemplate(): ChargingStationInfo { const stationTemplate: ChargingStationTemplate | undefined = this.getTemplateFromFile(); if (Utils.isNullOrUndefined(stationTemplate)) { @@ -866,31 +887,7 @@ export class ChargingStation { logger.error(`${this.logPrefix()} ${errorMsg}`); throw new BaseError(errorMsg); } - // Deprecation template keys section - ChargingStationUtils.warnDeprecatedTemplateKey( - stationTemplate, - 'supervisionUrl', - this.templateFile, - this.logPrefix(), - "Use 'supervisionUrls' instead" - ); - ChargingStationUtils.convertDeprecatedTemplateKey( - stationTemplate, - 'supervisionUrl', - 'supervisionUrls' - ); - ChargingStationUtils.warnDeprecatedTemplateKey( - stationTemplate, - 'authorizationFile', - this.templateFile, - this.logPrefix(), - "Use 'idTagsFile' instead" - ); - ChargingStationUtils.convertDeprecatedTemplateKey( - stationTemplate, - 'authorizationFile', - 'idTagsFile' - ); + this.warnTemplateKeysDeprecation(stationTemplate); const stationInfo: ChargingStationInfo = ChargingStationUtils.stationTemplateToStationInfo(stationTemplate); stationInfo.hashId = ChargingStationUtils.getHashId(this.index, stationTemplate); -- 2.34.1