X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcharging-station%2Focpp%2FOCPPServiceUtils.ts;h=46603f0bffeb6c34bd70b8b9c3c73a6cc52f4489;hb=d71ce3fa734fcefeb3dce31d78968b847c625c92;hp=8036079a4b2031c67613bf69ec5744e59cd9ae65;hpb=5bb45fe6de9568b7f9cb52435654b624e0125251;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/OCPPServiceUtils.ts b/src/charging-station/ocpp/OCPPServiceUtils.ts index 8036079a..46603f0b 100644 --- a/src/charging-station/ocpp/OCPPServiceUtils.ts +++ b/src/charging-station/ocpp/OCPPServiceUtils.ts @@ -41,6 +41,7 @@ import { isNotEmptyString, logPrefix, logger, + max, min, } from '../../utils'; @@ -418,22 +419,26 @@ export class OCPPServiceUtils { protected static getLimitFromSampledValueTemplateCustomValue( value: string, - limit: number, - options?: { limitationEnabled?: boolean; unitMultiplier?: number; defaultValue?: number }, + 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); if (options?.limitationEnabled) { - return min((!isNaN(parsedValue) ? parsedValue : Infinity) * 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 {