From 90befdb882c3c0d68878dad7985612c01ed19d8d Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 8 May 2022 22:49:46 +0200 Subject: [PATCH] Add missing src/charging-station/ocpp/OCPPServiceUtils.ts file MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ocpp/OCPPServiceUtils.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/charging-station/ocpp/OCPPServiceUtils.ts diff --git a/src/charging-station/ocpp/OCPPServiceUtils.ts b/src/charging-station/ocpp/OCPPServiceUtils.ts new file mode 100644 index 00000000..9d7cf620 --- /dev/null +++ b/src/charging-station/ocpp/OCPPServiceUtils.ts @@ -0,0 +1,16 @@ +export class OCPPServiceUtils { + protected static getLimitFromSampledValueTemplateCustomValue( + value: string, + limit: number, + options: { limitationEnabled?: boolean; unitMultiplier?: number } = { + limitationEnabled: true, + unitMultiplier: 1, + } + ): number { + options.limitationEnabled = options?.limitationEnabled ?? true; + options.unitMultiplier = options?.unitMultiplier ?? 1; + return options?.limitationEnabled + ? Math.min(parseInt(value) * options.unitMultiplier, limit) + : parseInt(value) * options.unitMultiplier; + } +} -- 2.34.1