-
- public static workerDynamicPoolInUse(): boolean {
- return Configuration.getWorker().processType === WorkerProcessType.dynamicPool;
- }
-
- public static warnTemplateKeysDeprecation(
- templateFile: string,
- stationTemplate: ChargingStationTemplate,
- logPrefix: string
- ) {
- const templateKeys: { key: string; deprecatedKey: string }[] = [
- { key: 'supervisionUrls', deprecatedKey: 'supervisionUrl' },
- { key: 'idTagsFile', deprecatedKey: 'authorizationFile' },
- ];
- for (const templateKey of templateKeys) {
- ChargingStationUtils.warnDeprecatedTemplateKey(
- stationTemplate,
- templateKey.deprecatedKey,
- templateFile,
- logPrefix,
- `Use '${templateKey.key}' instead`
- );
- ChargingStationUtils.convertDeprecatedTemplateKey(
- stationTemplate,
- templateKey.deprecatedKey,
- templateKey.key
- );
- }
- }
-
- public static stationTemplateToStationInfo(
- stationTemplate: ChargingStationTemplate
- ): ChargingStationInfo {
- stationTemplate = Utils.cloneObject(stationTemplate);
- delete stationTemplate.power;
- delete stationTemplate.powerUnit;
- delete stationTemplate.Configuration;
- delete stationTemplate.AutomaticTransactionGenerator;
- delete stationTemplate.chargeBoxSerialNumberPrefix;
- delete stationTemplate.chargePointSerialNumberPrefix;
- delete stationTemplate.meterSerialNumberPrefix;
- return stationTemplate as unknown as ChargingStationInfo;
- }
-
- public static createStationInfoHash(stationInfo: ChargingStationInfo): void {
- delete stationInfo.infoHash;
- stationInfo.infoHash = crypto
- .createHash(Constants.DEFAULT_HASH_ALGORITHM)
- .update(JSON.stringify(stationInfo))
- .digest('hex');
- }
-
- public static createSerialNumber(
- stationTemplate: ChargingStationTemplate,
- stationInfo: ChargingStationInfo,
- params: {
- randomSerialNumberUpperCase?: boolean;
- randomSerialNumber?: boolean;
- } = {
- randomSerialNumberUpperCase: true,
- randomSerialNumber: true,
- }
- ): void {
- params = params ?? {};
- params.randomSerialNumberUpperCase = params?.randomSerialNumberUpperCase ?? true;
- params.randomSerialNumber = params?.randomSerialNumber ?? true;
- const serialNumberSuffix = params?.randomSerialNumber
- ? ChargingStationUtils.getRandomSerialNumberSuffix({
- upperCase: params.randomSerialNumberUpperCase,
- })
- : '';
- stationInfo.chargePointSerialNumber = Utils.isNotEmptyString(
- stationTemplate?.chargePointSerialNumberPrefix
- )
- ? `${stationTemplate.chargePointSerialNumberPrefix}${serialNumberSuffix}`
- : undefined;
- stationInfo.chargeBoxSerialNumber = Utils.isNotEmptyString(
- stationTemplate?.chargeBoxSerialNumberPrefix
- )
- ? `${stationTemplate.chargeBoxSerialNumberPrefix}${serialNumberSuffix}`
- : undefined;
- stationInfo.meterSerialNumber = Utils.isNotEmptyString(stationTemplate?.meterSerialNumberPrefix)
- ? `${stationTemplate.meterSerialNumberPrefix}${serialNumberSuffix}`
- : undefined;
- }
-
- public static propagateSerialNumber(
- stationTemplate: ChargingStationTemplate,
- stationInfoSrc: ChargingStationInfo,
- stationInfoDst: ChargingStationInfo
- ) {
- if (!stationInfoSrc || !stationTemplate) {
- throw new BaseError(
- 'Missing charging station template or existing configuration to propagate serial number'
- );
- }
- stationTemplate?.chargePointSerialNumberPrefix && stationInfoSrc?.chargePointSerialNumber
- ? (stationInfoDst.chargePointSerialNumber = stationInfoSrc.chargePointSerialNumber)
- : stationInfoDst?.chargePointSerialNumber && delete stationInfoDst.chargePointSerialNumber;
- stationTemplate?.chargeBoxSerialNumberPrefix && stationInfoSrc?.chargeBoxSerialNumber
- ? (stationInfoDst.chargeBoxSerialNumber = stationInfoSrc.chargeBoxSerialNumber)
- : stationInfoDst?.chargeBoxSerialNumber && delete stationInfoDst.chargeBoxSerialNumber;
- stationTemplate?.meterSerialNumberPrefix && stationInfoSrc?.meterSerialNumber
- ? (stationInfoDst.meterSerialNumber = stationInfoSrc.meterSerialNumber)
- : stationInfoDst?.meterSerialNumber && delete stationInfoDst.meterSerialNumber;
+ stationTemplate?.chargePointSerialNumberPrefix && stationInfoSrc?.chargePointSerialNumber
+ ? (stationInfoDst.chargePointSerialNumber = stationInfoSrc.chargePointSerialNumber)
+ : stationInfoDst?.chargePointSerialNumber && delete stationInfoDst.chargePointSerialNumber;
+ stationTemplate?.chargeBoxSerialNumberPrefix && stationInfoSrc?.chargeBoxSerialNumber
+ ? (stationInfoDst.chargeBoxSerialNumber = stationInfoSrc.chargeBoxSerialNumber)
+ : stationInfoDst?.chargeBoxSerialNumber && delete stationInfoDst.chargeBoxSerialNumber;
+ stationTemplate?.meterSerialNumberPrefix && stationInfoSrc?.meterSerialNumber
+ ? (stationInfoDst.meterSerialNumber = stationInfoSrc.meterSerialNumber)
+ : stationInfoDst?.meterSerialNumber && delete stationInfoDst.meterSerialNumber;
+};
+
+export const getAmperageLimitationUnitDivider = (stationInfo: ChargingStationInfo): number => {
+ let unitDivider = 1;
+ switch (stationInfo.amperageLimitationUnit) {
+ case AmpereUnits.DECI_AMPERE:
+ unitDivider = 10;
+ break;
+ case AmpereUnits.CENTI_AMPERE:
+ unitDivider = 100;
+ break;
+ case AmpereUnits.MILLI_AMPERE:
+ unitDivider = 1000;
+ break;
+ }
+ return unitDivider;
+};
+
+export const getChargingStationConnectorChargingProfilesPowerLimit = (
+ chargingStation: ChargingStation,
+ connectorId: number
+): number | undefined => {
+ let limit: number, matchingChargingProfile: ChargingProfile;
+ // Get charging profiles for connector and sort by stack level
+ const chargingProfiles =
+ cloneObject<ChargingProfile[]>(
+ chargingStation.getConnectorStatus(connectorId)?.chargingProfiles
+ )?.sort((a, b) => b.stackLevel - a.stackLevel) ?? [];
+ // Get profiles on connector 0
+ if (chargingStation.getConnectorStatus(0)?.chargingProfiles) {
+ chargingProfiles.push(
+ ...cloneObject<ChargingProfile[]>(
+ chargingStation.getConnectorStatus(0).chargingProfiles
+ ).sort((a, b) => b.stackLevel - a.stackLevel)
+ );