From: Jérôme Benoit Date: Mon, 23 May 2022 21:15:16 +0000 (+0200) Subject: Fix serial number propagation at charging station template change X-Git-Tag: v1.1.61~32 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=fec4d204dd05c108fb49312bb7a570d15a4eb4bb;p=e-mobility-charging-stations-simulator.git Fix serial number propagation at charging station template change Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 96d889ee..064e33ad 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -826,7 +826,12 @@ export default class ChargingStation { } return stationInfoFromFile; } - ChargingStationUtils.createSerialNumber(this.getTemplateFromFile(), stationInfoFromFile); + stationInfoFromFile && + ChargingStationUtils.propagateSerialNumber( + this.getTemplateFromFile(), + stationInfoFromFile, + stationInfoFromTemplate + ); return stationInfoFromTemplate; } diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index b57e98e6..582912b0 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,6 +230,7 @@ export class ChargingStationUtils { delete stationTemplate.AutomaticTransactionGenerator; delete stationTemplate.chargeBoxSerialNumberPrefix; delete stationTemplate.chargePointSerialNumberPrefix; + delete stationTemplate.meterSerialNumberPrefix; return stationTemplate; } @@ -251,7 +253,7 @@ export class ChargingStationUtils { public static createSerialNumber( stationTemplate: ChargingStationTemplate, - stationInfo: ChargingStationInfo, + stationInfo: ChargingStationInfo = {} as ChargingStationInfo, params: { randomSerialNumberUpperCase?: boolean; randomSerialNumber?: boolean; @@ -268,24 +270,34 @@ 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 info 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 { diff --git a/src/types/ChargingStationInfo.ts b/src/types/ChargingStationInfo.ts index 1c6415ae..2baa72ef 100644 --- a/src/types/ChargingStationInfo.ts +++ b/src/types/ChargingStationInfo.ts @@ -9,6 +9,7 @@ export default interface ChargingStationInfo | 'powerUnit' | 'chargeBoxSerialNumberPrefix' | 'chargePointSerialNumberPrefix' + | 'meterSerialNumberPrefix' > { infoHash?: string; chargingStationId?: string; diff --git a/src/types/ocpp/1.6/Requests.ts b/src/types/ocpp/1.6/Requests.ts index 31825e16..1499e4ff 100644 --- a/src/types/ocpp/1.6/Requests.ts +++ b/src/types/ocpp/1.6/Requests.ts @@ -36,15 +36,15 @@ export enum OCPP16IncomingRequestCommand { export type OCPP16HeartbeatRequest = EmptyObject; export interface OCPP16BootNotificationRequest extends JsonObject { - chargeBoxSerialNumber?: string; + chargePointVendor: string; chargePointModel: string; chargePointSerialNumber?: string; - chargePointVendor: string; + chargeBoxSerialNumber?: string; firmwareVersion?: string; iccid?: string; imsi?: string; - meterSerialNumber?: string; meterType?: string; + meterSerialNumber?: string; } export interface OCPP16StatusNotificationRequest extends JsonObject {