isNotEmptyString,
logPrefix,
logger,
+ max,
min,
} from '../../utils';
}
protected static getLimitFromSampledValueTemplateCustomValue(
- value: string,
- limit: number,
- options?: { limitationEnabled?: boolean; unitMultiplier?: number; defaultValue?: number },
+ value: string | undefined,
+ maxLimit: number,
+ minLimit: number,
+ options?: { limitationEnabled?: boolean; fallbackValue?: number; unitMultiplier?: number },
): number {
options = {
...{
limitationEnabled: true,
unitMultiplier: 1,
- defaultValue: 0,
+ fallbackValue: 0,
},
...options,
};
- const parsedValue = parseInt(value);
+ const parsedValue = parseInt(value ?? '');
if (options?.limitationEnabled) {
- const numberValue = !isNaN(parsedValue) ? parsedValue : Infinity;
- return min(numberValue * options.unitMultiplier!, limit);
+ return max(
+ min((!isNaN(parsedValue) ? parsedValue : Infinity) * options.unitMultiplier!, maxLimit),
+ minLimit,
+ );
}
- return (!isNaN(parsedValue) ? parsedValue : options.defaultValue!) * options.unitMultiplier!;
+ return (!isNaN(parsedValue) ? parsedValue : options.fallbackValue!) * options.unitMultiplier!;
}
private static isIdTagLocalAuthorized(chargingStation: ChargingStation, idTag: string): boolean {