-
- public static workerDynamicPoolInUse(): boolean {
- return Configuration.getWorker().processType === WorkerProcessType.dynamicPool;
- }
-
- public static warnTemplateKeysDeprecation(
- templateFile: string,
- stationTemplate: ChargingStationTemplate,
- logPrefix: string
- ) {
- const templateKeys: { key: string; deprecatedKey: string }[] = [
- { key: 'supervisionUrls', deprecatedKey: 'supervisionUrl' },
- { key: 'idTagsFile', deprecatedKey: 'authorizationFile' },
- ];
- for (const templateKey of templateKeys) {
- ChargingStationUtils.warnDeprecatedTemplateKey(
- stationTemplate,
- templateKey.deprecatedKey,
- templateFile,
- logPrefix,
- `Use '${templateKey.key}' instead`
- );
- ChargingStationUtils.convertDeprecatedTemplateKey(
- stationTemplate,
- templateKey.deprecatedKey,
- templateKey.key
- );
- }
- }
-
- public static stationTemplateToStationInfo(
- stationTemplate: ChargingStationTemplate
- ): ChargingStationInfo {
- stationTemplate = Utils.cloneObject(stationTemplate);
- delete stationTemplate.power;
- delete stationTemplate.powerUnit;
- delete stationTemplate.Configuration;
- delete stationTemplate.AutomaticTransactionGenerator;
- delete stationTemplate.chargeBoxSerialNumberPrefix;
- delete stationTemplate.chargePointSerialNumberPrefix;
- delete stationTemplate.meterSerialNumberPrefix;
- return stationTemplate as unknown as ChargingStationInfo;
+};
+
+export const stationTemplateToStationInfo = (
+ stationTemplate: ChargingStationTemplate,
+): ChargingStationInfo => {
+ stationTemplate = cloneObject<ChargingStationTemplate>(stationTemplate);
+ delete stationTemplate.power;
+ delete stationTemplate.powerUnit;
+ delete stationTemplate.Connectors;
+ delete stationTemplate.Evses;
+ delete stationTemplate.Configuration;
+ delete stationTemplate.AutomaticTransactionGenerator;
+ delete stationTemplate.chargeBoxSerialNumberPrefix;
+ delete stationTemplate.chargePointSerialNumberPrefix;
+ delete stationTemplate.meterSerialNumberPrefix;
+ return stationTemplate as unknown as ChargingStationInfo;
+};
+
+export const createSerialNumber = (
+ stationTemplate: ChargingStationTemplate,
+ stationInfo: ChargingStationInfo,
+ params: {
+ randomSerialNumberUpperCase?: boolean;
+ randomSerialNumber?: boolean;
+ } = {
+ randomSerialNumberUpperCase: true,
+ randomSerialNumber: true,
+ },
+): void => {
+ params = { ...{ randomSerialNumberUpperCase: true, randomSerialNumber: true }, ...params };
+ const serialNumberSuffix = params?.randomSerialNumber
+ ? getRandomSerialNumberSuffix({
+ upperCase: params.randomSerialNumberUpperCase,
+ })
+ : '';
+ isNotEmptyString(stationTemplate?.chargePointSerialNumberPrefix) &&
+ (stationInfo.chargePointSerialNumber = `${stationTemplate.chargePointSerialNumberPrefix}${serialNumberSuffix}`);
+ isNotEmptyString(stationTemplate?.chargeBoxSerialNumberPrefix) &&
+ (stationInfo.chargeBoxSerialNumber = `${stationTemplate.chargeBoxSerialNumberPrefix}${serialNumberSuffix}`);
+ isNotEmptyString(stationTemplate?.meterSerialNumberPrefix) &&
+ (stationInfo.meterSerialNumber = `${stationTemplate.meterSerialNumberPrefix}${serialNumberSuffix}`);
+};
+
+export const propagateSerialNumber = (
+ stationTemplate: ChargingStationTemplate,
+ stationInfoSrc: ChargingStationInfo,
+ stationInfoDst: ChargingStationInfo,
+) => {
+ if (!stationInfoSrc || !stationTemplate) {
+ throw new BaseError(
+ 'Missing charging station template or existing configuration to propagate serial number',
+ );