From efb85e20f26ef140f7a293de7404d23ddf11bb38 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 13 Mar 2022 22:46:53 +0100 Subject: [PATCH] Use right station info attributes for serial number 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 | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index d9840987..dc679b84 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -759,6 +759,19 @@ export default class ChargingStation { idSuffix; } + private getRandomSerialNumberSuffix(params?: { + randomBytesLength?: number; + upperCase?: boolean; + }): string { + const randomSerialNumberSuffix = crypto + .randomBytes(params?.randomBytesLength ?? 16) + .toString('hex'); + if (params?.upperCase) { + return randomSerialNumberSuffix.toUpperCase(); + } + return randomSerialNumberSuffix; + } + private buildStationInfo(): ChargingStationInfo { let stationTemplateFromFile: ChargingStationTemplate; try { @@ -784,6 +797,10 @@ export default class ChargingStation { ); this.convertDeprecatedTemplateKey(stationTemplateFromFile, 'supervisionUrl', 'supervisionUrls'); const stationInfo: ChargingStationInfo = stationTemplateFromFile ?? ({} as ChargingStationInfo); + stationInfo.chargePointSerialNumber = stationTemplateFromFile?.chargePointSerialNumberPrefix; + delete stationInfo.chargePointSerialNumberPrefix; + stationInfo.chargeBoxSerialNumber = stationTemplateFromFile?.chargeBoxSerialNumberPrefix; + delete stationInfo.chargeBoxSerialNumberPrefix; stationInfo.wsOptions = stationTemplateFromFile?.wsOptions ?? {}; if (!Utils.isEmptyArray(stationTemplateFromFile.power)) { stationTemplateFromFile.power = stationTemplateFromFile.power as number[]; @@ -831,11 +848,11 @@ export default class ChargingStation { this.bootNotificationRequest = { chargePointModel: this.stationInfo.chargePointModel, chargePointVendor: this.stationInfo.chargePointVendor, - ...(!Utils.isUndefined(this.stationInfo.chargeBoxSerialNumberPrefix) && { - chargeBoxSerialNumber: this.stationInfo.chargeBoxSerialNumberPrefix, + ...(!Utils.isUndefined(this.stationInfo.chargeBoxSerialNumber) && { + chargeBoxSerialNumber: this.stationInfo.chargeBoxSerialNumber, }), - ...(!Utils.isUndefined(this.stationInfo.chargePointSerialNumberPrefix) && { - chargePointSerialNumber: this.stationInfo.chargePointSerialNumberPrefix, + ...(!Utils.isUndefined(this.stationInfo.chargePointSerialNumber) && { + chargePointSerialNumber: this.stationInfo.chargePointSerialNumber, }), ...(!Utils.isUndefined(this.stationInfo.firmwareVersion) && { firmwareVersion: this.stationInfo.firmwareVersion, -- 2.34.1