From 3ead11bafea04b49a11a4a3fe9a0e19750c952fa Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 27 Apr 2022 17:55:33 +0200 Subject: [PATCH] Simplify logic in createStationInfoHash() CS method 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 | 30 +++++++++++++------------ 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 690859e0..76a18e68 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -960,7 +960,7 @@ export default class ChargingStation { private getStationInfoFromTemplate(): ChargingStationInfo { const stationInfo: ChargingStationInfo = this.getTemplateFromFile(); if (Utils.isNullOrUndefined(stationInfo)) { - const logMsg = 'Fail to read charging station template file'; + const logMsg = 'Failed to read charging station template file'; logger.error(`${this.logPrefix()} ${logMsg}`); throw new BaseError(logMsg); } @@ -1001,19 +1001,21 @@ export default class ChargingStation { } private createStationInfoHash(stationInfo: ChargingStationInfo): ChargingStationInfo { - const previousInfoHash = stationInfo?.infoHash ?? ''; - delete stationInfo.infoHash; - const currentInfoHash = crypto - .createHash(Constants.DEFAULT_HASH_ALGORITHM) - .update(JSON.stringify(stationInfo)) - .digest('hex'); - if ( - (!Utils.isEmptyObject(stationInfo) && Utils.isEmptyString(previousInfoHash)) || - (!Utils.isEmptyString(previousInfoHash) && currentInfoHash !== previousInfoHash) - ) { - stationInfo.infoHash = currentInfoHash; - } else if (!Utils.isEmptyObject(stationInfo)) { - stationInfo.infoHash = previousInfoHash; + if (!Utils.isEmptyObject(stationInfo)) { + const previousInfoHash = stationInfo?.infoHash ?? ''; + delete stationInfo.infoHash; + const currentInfoHash = crypto + .createHash(Constants.DEFAULT_HASH_ALGORITHM) + .update(JSON.stringify(stationInfo)) + .digest('hex'); + if ( + Utils.isEmptyString(previousInfoHash) || + (!Utils.isEmptyString(previousInfoHash) && currentInfoHash !== previousInfoHash) + ) { + stationInfo.infoHash = currentInfoHash; + } else { + stationInfo.infoHash = previousInfoHash; + } } return stationInfo; } -- 2.34.1