Add missing src/charging-station/ocpp/OCPPServiceUtils.ts file
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 8 May 2022 20:49:46 +0000 (22:49 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 8 May 2022 20:49:46 +0000 (22:49 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/charging-station/ocpp/OCPPServiceUtils.ts [new file with mode: 0644]

diff --git a/src/charging-station/ocpp/OCPPServiceUtils.ts b/src/charging-station/ocpp/OCPPServiceUtils.ts
new file mode 100644 (file)
index 0000000..9d7cf62
--- /dev/null
@@ -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;
+  }
+}