Consistent naming for CS template enums
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 27 Jun 2021 13:16:36 +0000 (15:16 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 27 Jun 2021 13:16:36 +0000 (15:16 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/ocpp/1.6/OCPP16RequestService.ts
src/types/ChargingStationTemplate.ts

index 4c3179f45d18c0bf3b1bf8f007615c0ae23e1ed7..30b21bdc357bd2ab65c70e90c4232b5352961750 100644 (file)
@@ -1,6 +1,6 @@
 import { BootNotificationResponse, RegistrationStatus } from '../types/ocpp/Responses';
 import ChargingStationConfiguration, { ConfigurationKey } from '../types/ChargingStationConfiguration';
-import ChargingStationTemplate, { CurrentOutType, PowerUnits, VoltageOut } from '../types/ChargingStationTemplate';
+import ChargingStationTemplate, { CurrentType, PowerUnits, Voltage } from '../types/ChargingStationTemplate';
 import { ConnectorPhaseRotation, StandardParametersKey, SupportedFeatureProfiles } from '../types/ocpp/Configuration';
 import Connectors, { Connector, SampledValueTemplate } from '../types/Connectors';
 import { MeterValueMeasurand, MeterValuePhase } from '../types/ocpp/MeterValues';
@@ -93,9 +93,9 @@ export default class ChargingStation {
 
   public getNumberOfPhases(): number | undefined {
     switch (this.getCurrentOutType()) {
-      case CurrentOutType.AC:
+      case CurrentType.AC:
         return !Utils.isUndefined(this.stationInfo.numberOfPhases) ? this.stationInfo.numberOfPhases : 3;
-      case CurrentOutType.DC:
+      case CurrentType.DC:
         return 0;
     }
   }
@@ -120,19 +120,19 @@ export default class ChargingStation {
     return this.connectors[id];
   }
 
-  public getCurrentOutType(): CurrentOutType | undefined {
-    return this.stationInfo.currentOutType ?? CurrentOutType.AC;
+  public getCurrentOutType(): CurrentType | undefined {
+    return this.stationInfo.currentOutType ?? CurrentType.AC;
   }
 
   public getVoltageOut(): number | undefined {
     const errMsg = `${this.logPrefix()} Unknown ${this.getCurrentOutType()} currentOutType in template file ${this.stationTemplateFile}, cannot define default voltage out`;
     let defaultVoltageOut: number;
     switch (this.getCurrentOutType()) {
-      case CurrentOutType.AC:
-        defaultVoltageOut = VoltageOut.VOLTAGE_230;
+      case CurrentType.AC:
+        defaultVoltageOut = Voltage.VOLTAGE_230;
         break;
-      case CurrentOutType.DC:
-        defaultVoltageOut = VoltageOut.VOLTAGE_400;
+      case CurrentType.DC:
+        defaultVoltageOut = Voltage.VOLTAGE_400;
         break;
       default:
         logger.error(errMsg);
index eb502d6ef38c84bf28cce7ca3aaeb8fc01798676..74bc1fbf2d1dcd66ab3cf805d829954b18ff7371 100644 (file)
@@ -1,6 +1,6 @@
 import { ACElectricUtils, DCElectricUtils } from '../../../utils/ElectricUtils';
 import { AuthorizeRequest, OCPP16AuthorizeResponse, OCPP16StartTransactionResponse, OCPP16StopTransactionReason, OCPP16StopTransactionResponse, StartTransactionRequest, StopTransactionRequest } from '../../../types/ocpp/1.6/Transaction';
-import { CurrentOutType, VoltageOut } from '../../../types/ChargingStationTemplate';
+import { CurrentType, Voltage } from '../../../types/ChargingStationTemplate';
 import { HeartbeatRequest, OCPP16BootNotificationRequest, OCPP16IncomingRequestCommand, OCPP16RequestCommand, StatusNotificationRequest } from '../../../types/ocpp/1.6/Requests';
 import { MeterValueUnit, MeterValuesRequest, OCPP16MeterValue, OCPP16MeterValueMeasurand, OCPP16MeterValuePhase } from '../../../types/ocpp/1.6/MeterValues';
 
@@ -158,11 +158,11 @@ export default class OCPP16RequestService extends OCPPRequestService {
             const voltagePhaseLineToLineSampledValueTemplate = self.chargingStation.getSampledValueTemplate(connectorId, OCPP16MeterValueMeasurand.VOLTAGE, phaseLineToLineValue as OCPP16MeterValuePhase);
             let voltagePhaseLineToLineMeasurandValue: number;
             if (voltagePhaseLineToLineSampledValueTemplate) {
-              const voltagePhaseLineToLineSampledValueTemplateValue = voltagePhaseLineToLineSampledValueTemplate.value ? parseInt(voltagePhaseLineToLineSampledValueTemplate.value) : VoltageOut.VOLTAGE_400;
+              const voltagePhaseLineToLineSampledValueTemplateValue = voltagePhaseLineToLineSampledValueTemplate.value ? parseInt(voltagePhaseLineToLineSampledValueTemplate.value) : Voltage.VOLTAGE_400;
               const fluctuationPhaseLineToLinePercent = voltagePhaseLineToLineSampledValueTemplate.fluctuationPercent ?? Constants.DEFAULT_FLUCTUATION_PERCENT;
               voltagePhaseLineToLineMeasurandValue = Utils.getRandomFloatFluctuatedRounded(voltagePhaseLineToLineSampledValueTemplateValue, fluctuationPhaseLineToLinePercent);
             }
-            const defaultVoltagePhaseLineToLineMeasurandValue = Utils.getRandomFloatFluctuatedRounded(VoltageOut.VOLTAGE_400, fluctuationPercent);
+            const defaultVoltagePhaseLineToLineMeasurandValue = Utils.getRandomFloatFluctuatedRounded(Voltage.VOLTAGE_400, fluctuationPercent);
             meterValue.sampledValue.push(OCPP16ServiceUtils.buildSampledValue(voltagePhaseLineToLineSampledValueTemplate ?? voltageSampledValueTemplate,
               voltagePhaseLineToLineMeasurandValue ?? defaultVoltagePhaseLineToLineMeasurandValue, null, phaseLineToLineValue as OCPP16MeterValuePhase));
           }
@@ -186,7 +186,7 @@ export default class OCPP16RequestService extends OCPPRequestService {
         const maxPower = Math.round(self.chargingStation.stationInfo.maxPower / self.chargingStation.stationInfo.powerDivider);
         const maxPowerPerPhase = Math.round((self.chargingStation.stationInfo.maxPower / self.chargingStation.stationInfo.powerDivider) / self.chargingStation.getNumberOfPhases());
         switch (self.chargingStation.getCurrentOutType()) {
-          case CurrentOutType.AC:
+          case CurrentType.AC:
             if (self.chargingStation.getNumberOfPhases() === 3) {
               const defaultFluctuatedPowerPerPhase = powerSampledValueTemplate.value
                 && Utils.getRandomFloatFluctuatedRounded(parseInt(powerSampledValueTemplate.value) / self.chargingStation.getNumberOfPhases(), powerSampledValueTemplate.fluctuationPercent ?? Constants.DEFAULT_FLUCTUATION_PERCENT);
@@ -208,7 +208,7 @@ export default class OCPP16RequestService extends OCPPRequestService {
             }
             powerMeasurandValues.allPhases = Utils.roundTo(powerMeasurandValues.L1 + powerMeasurandValues.L2 + powerMeasurandValues.L3, 2);
             break;
-          case CurrentOutType.DC:
+          case CurrentType.DC:
             powerMeasurandValues.allPhases = powerSampledValueTemplate.value
               ? Utils.getRandomFloatFluctuatedRounded(parseInt(powerSampledValueTemplate.value), powerSampledValueTemplate.fluctuationPercent ?? Constants.DEFAULT_FLUCTUATION_PERCENT)
               : Utils.getRandomFloatRounded(maxPower / unitDivider);
@@ -250,7 +250,7 @@ export default class OCPP16RequestService extends OCPPRequestService {
         const currentMeasurandValues: MeasurandValues = {} as MeasurandValues;
         let maxAmperage: number;
         switch (self.chargingStation.getCurrentOutType()) {
-          case CurrentOutType.AC:
+          case CurrentType.AC:
             maxAmperage = ACElectricUtils.amperagePerPhaseFromPower(self.chargingStation.getNumberOfPhases(), self.chargingStation.stationInfo.maxPower / self.chargingStation.stationInfo.powerDivider, self.chargingStation.getVoltageOut());
             if (self.chargingStation.getNumberOfPhases() === 3) {
               const defaultFluctuatedAmperagePerPhase = currentSampledValueTemplate.value
@@ -273,7 +273,7 @@ export default class OCPP16RequestService extends OCPPRequestService {
             }
             currentMeasurandValues.allPhases = Utils.roundTo((currentMeasurandValues.L1 + currentMeasurandValues.L2 + currentMeasurandValues.L3) / self.chargingStation.getNumberOfPhases(), 2);
             break;
-          case CurrentOutType.DC:
+          case CurrentType.DC:
             maxAmperage = DCElectricUtils.amperage(self.chargingStation.stationInfo.maxPower / self.chargingStation.stationInfo.powerDivider, self.chargingStation.getVoltageOut());
             currentMeasurandValues.allPhases = currentSampledValueTemplate.value
               ? Utils.getRandomFloatFluctuatedRounded(parseInt(currentSampledValueTemplate.value), currentSampledValueTemplate.fluctuationPercent ?? Constants.DEFAULT_FLUCTUATION_PERCENT)
index 5fff748bdbdad42c4718ac6d75e672e83b436a49..fd1d988f02e73e40c185bc3f2dcf32fa6eb89e24 100644 (file)
@@ -3,7 +3,7 @@ import Connectors from './Connectors';
 import { OCPPProtocol } from './ocpp/OCPPProtocol';
 import { OCPPVersion } from './ocpp/OCPPVersion';
 
-export enum CurrentOutType {
+export enum CurrentType {
   AC = 'AC',
   DC = 'DC',
 }
@@ -13,7 +13,7 @@ export enum PowerUnits {
   KILO_WATT = 'kW',
 }
 
-export enum VoltageOut {
+export enum Voltage {
   VOLTAGE_110 = 110,
   VOLTAGE_230 = 230,
   VOLTAGE_400 = 400,
@@ -47,8 +47,8 @@ export default interface ChargingStationTemplate {
   power: number | number[];
   powerSharedByConnectors?: boolean;
   powerUnit: PowerUnits;
-  currentOutType?: CurrentOutType;
-  voltageOut?: number;
+  currentOutType?: CurrentType;
+  voltageOut?: Voltage;
   numberOfPhases?: number;
   numberOfConnectors?: number | number[];
   useConnectorId0?: boolean;