X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FChargingStationUtils.ts;h=9eee346630083ee75dc623af9b16c6ff14704d0f;hb=8bea4a18973485e1b98d153c45447841f622b701;hp=b57e98e6741222f309d04d8ac84ed3ccbf4bec37;hpb=fa7bccf4a465d2156c43a3b5f33f0b521da52dc3;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index b57e98e6..9eee3466 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -7,6 +7,7 @@ import ChargingStationTemplate, { } from '../types/ChargingStationTemplate'; import { MeterValueMeasurand, MeterValuePhase } from '../types/ocpp/MeterValues'; +import BaseError from '../exception/BaseError'; import { BootNotificationRequest } from '../types/ocpp/Requests'; import ChargingStation from './ChargingStation'; import { ChargingStationConfigurationUtils } from './ChargingStationConfigurationUtils'; @@ -229,29 +230,21 @@ export class ChargingStationUtils { delete stationTemplate.AutomaticTransactionGenerator; delete stationTemplate.chargeBoxSerialNumberPrefix; delete stationTemplate.chargePointSerialNumberPrefix; + delete stationTemplate.meterSerialNumberPrefix; return stationTemplate; } public static createStationInfoHash(stationInfo: ChargingStationInfo): void { - const previousInfoHash = stationInfo?.infoHash ?? ''; delete stationInfo.infoHash; - const currentInfoHash = crypto + stationInfo.infoHash = 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; - } } public static createSerialNumber( stationTemplate: ChargingStationTemplate, - stationInfo: ChargingStationInfo, + stationInfo: ChargingStationInfo = {} as ChargingStationInfo, params: { randomSerialNumberUpperCase?: boolean; randomSerialNumber?: boolean; @@ -268,24 +261,36 @@ export class ChargingStationUtils { upperCase: params.randomSerialNumberUpperCase, }) : ''; - stationTemplate?.chargePointSerialNumberPrefix && - stationInfo && - Utils.isNullOrUndefined(stationInfo?.chargePointSerialNumber) - ? (stationInfo.chargePointSerialNumber = - stationTemplate.chargePointSerialNumberPrefix + serialNumberSuffix) - : stationInfo && delete stationInfo.chargePointSerialNumber; - stationTemplate?.chargeBoxSerialNumberPrefix && - stationInfo && - Utils.isNullOrUndefined(stationInfo?.chargeBoxSerialNumber) - ? (stationInfo.chargeBoxSerialNumber = - stationTemplate.chargeBoxSerialNumberPrefix + serialNumberSuffix) - : stationInfo && delete stationInfo.chargeBoxSerialNumber; - stationTemplate?.meterSerialNumberPrefix && - stationInfo && - Utils.isNullOrUndefined(stationInfo?.meterSerialNumber) - ? (stationInfo.meterSerialNumber = - stationTemplate.meterSerialNumberPrefix + serialNumberSuffix) - : stationInfo && delete stationInfo.meterSerialNumber; + stationInfo.chargePointSerialNumber = + stationTemplate?.chargePointSerialNumberPrefix && + stationTemplate.chargePointSerialNumberPrefix + serialNumberSuffix; + stationInfo.chargeBoxSerialNumber = + stationTemplate?.chargeBoxSerialNumberPrefix && + stationTemplate.chargeBoxSerialNumberPrefix + serialNumberSuffix; + stationInfo.meterSerialNumber = + stationTemplate?.meterSerialNumberPrefix && + stationTemplate.meterSerialNumberPrefix + serialNumberSuffix; + } + + public static propagateSerialNumber( + stationTemplate: ChargingStationTemplate, + stationInfoSrc: ChargingStationInfo, + stationInfoDst: ChargingStationInfo = {} as ChargingStationInfo + ) { + if (!stationInfoSrc || !stationTemplate) { + throw new BaseError( + 'Missing charging station template or existing configuration to propagate serial number' + ); + } + stationTemplate?.chargePointSerialNumberPrefix && stationInfoSrc?.chargePointSerialNumber + ? (stationInfoDst.chargePointSerialNumber = stationInfoSrc.chargePointSerialNumber) + : stationInfoDst?.chargePointSerialNumber && delete stationInfoDst.chargePointSerialNumber; + stationTemplate?.chargeBoxSerialNumberPrefix && stationInfoSrc?.chargeBoxSerialNumber + ? (stationInfoDst.chargeBoxSerialNumber = stationInfoSrc.chargeBoxSerialNumber) + : stationInfoDst?.chargeBoxSerialNumber && delete stationInfoDst.chargeBoxSerialNumber; + stationTemplate?.meterSerialNumberPrefix && stationInfoSrc?.meterSerialNumber + ? (stationInfoDst.meterSerialNumber = stationInfoSrc.meterSerialNumber) + : stationInfoDst?.meterSerialNumber && delete stationInfoDst.meterSerialNumber; } public static getAmperageLimitationUnitDivider(stationInfo: ChargingStationInfo): number {