repositories
/
e-mobility-charging-stations-simulator.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix: ensure event listeners are always removed at simulator stop
[e-mobility-charging-stations-simulator.git]
/
src
/
charging-station
/
ocpp
/
OCPPServiceUtils.ts
diff --git
a/src/charging-station/ocpp/OCPPServiceUtils.ts
b/src/charging-station/ocpp/OCPPServiceUtils.ts
index 3a1423c4679ce0561b46df3f30d58dc5da0f7189..d9d712981c816790cb4e2b6f1c09fa6cd10e7dac 100644
(file)
--- a/
src/charging-station/ocpp/OCPPServiceUtils.ts
+++ b/
src/charging-station/ocpp/OCPPServiceUtils.ts
@@
-41,6
+41,7
@@
import {
isNotEmptyString,
logPrefix,
logger,
isNotEmptyString,
logPrefix,
logger,
+ max,
min,
} from '../../utils';
min,
} from '../../utils';
@@
-417,24
+418,27
@@
export class OCPPServiceUtils {
}
protected static getLimitFromSampledValueTemplateCustomValue(
}
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 = {
...{
): number {
options = {
...{
- limitationEnabled:
tru
e,
+ limitationEnabled:
fals
e,
unitMultiplier: 1,
unitMultiplier: 1,
-
default
Value: 0,
+
fallback
Value: 0,
},
...options,
};
},
...options,
};
- const parsedValue = parseInt(value);
+ const parsedValue = parseInt(value
?? ''
);
if (options?.limitationEnabled) {
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.
default
Value!) * options.unitMultiplier!;
+ return (!isNaN(parsedValue) ? parsedValue : options.
fallback
Value!) * options.unitMultiplier!;
}
private static isIdTagLocalAuthorized(chargingStation: ChargingStation, idTag: string): boolean {
}
private static isIdTagLocalAuthorized(chargingStation: ChargingStation, idTag: string): boolean {