Added charge points in utils methods
MODIFY
src/integration/charging-station-vendor/ChargingStationVendorIntegration.ts
src/integration/charging-station-vendor/ChargingStationVendorIntegration.ts
@@ -493,7 +493,7 @@ export default abstract class ChargingStationVendorIntegration {
}
const result: ConnectorCurrentLimit = {
limitAmps: connectorLimitAmps,
- limitWatts: Utils.convertAmpToWatt(chargingStation, connectorID, connectorLimitAmps),
+ limitWatts: Utils.convertAmpToWatt(chargingStation, chargePoint, connectorID, connectorLimitAmps),
limitSource: ConnectorCurrentLimitSource.CHARGING_PROFILE,
};
Logging.logDebug({
@@ -527,7 +527,7 @@ export default abstract class ChargingStationVendorIntegration {
}
const result: ConnectorCurrentLimit = {
limitAmps: connectorLimitAmps,
- limitWatts: Utils.convertAmpToWatt(chargingStation, connectorID, connectorLimitAmps),
+ limitWatts: Utils.convertAmpToWatt(chargingStation, chargePoint, connectorID, connectorLimitAmps),
limitSource: ConnectorCurrentLimitSource.STATIC_LIMITATION,
};
Logging.logDebug({
@@ -588,7 +588,7 @@ export default abstract class ChargingStationVendorIntegration {
} else {
// Limit Watts for all the phases (Cahors)
schedulePeriod.limit = Utils.convertAmpToWatt(
- chargingStation, vendorSpecificChargingProfile.connectorID,
+ chargingStation, chargePoint, vendorSpecificChargingProfile.connectorID,
this.chargePointToConnectorLimitAmps(chargePoint, schedulePeriod.limit));
}
}
@@ -608,12 +608,12 @@ export default abstract class ChargingStationVendorIntegration {
// Convert to Amps for all phases
if (chargingSchedule.chargingRateUnit === ChargingRateUnitType.WATT) {
chargingSchedulePeriod['limitWatts'] = chargingSchedulePeriod.limit;
- chargingSchedulePeriod.limit = Utils.convertWattToAmp(chargingStation, connectorID, chargingSchedulePeriod.limit);
+ chargingSchedulePeriod.limit = Utils.convertWattToAmp(chargingStation, chargePoint, connectorID, chargingSchedulePeriod.limit);
}
// Limit is per connector and per phase Convert to max Amp
chargingSchedulePeriod.limit = this.convertLimitAmpToAllPhases(
chargingStation, chargePoint, connectorID, chargingSchedulePeriod.limit);
- chargingSchedulePeriod['limitWatts'] = Utils.convertAmpToWatt(chargingStation, connectorID, chargingSchedulePeriod.limit);
+ chargingSchedulePeriod['limitWatts'] = Utils.convertAmpToWatt(chargingStation, chargePoint, connectorID, chargingSchedulePeriod.limit);
}
}
// Convert to Amps?

MODIFY
src/migration/tasks/AddSiteAreaLimitToConsumptionsTask.ts
src/migration/tasks/AddSiteAreaLimitToConsumptionsTask.ts
@@ -31,22 +31,8 @@ export default class AddSiteAreaLimitToConsumptionsTask extends MigrationTask {
}
// Compute charging station power
for (const chargingStation of siteArea.chargingStations) {
- let limitAmps = 0;
- // Amps from chargepoint
- if (chargingStation.chargePoints) {
- for (const chargePoint of chargingStation.chargePoints) {
- limitAmps += Utils.getChargingStationAmperage(chargingStation, chargePoint);
- limitChargingStationsWatts += Utils.convertAmpToWatt(chargingStation, 0, limitAmps);
- }
- // Amps from connector
- } else {
- for (const connector of chargingStation.connectors) {
- if (connector.amperage) {
- limitAmps += connector.amperage;
- limitChargingStationsWatts += Utils.convertAmpToWatt(chargingStation, connector.connectorId, limitAmps);
- }
- }
- }
+ const limitAmps = Utils.getChargingStationAmperage(chargingStation);
+ limitChargingStationsWatts += Utils.convertAmpToWatt(chargingStation, null, 0, limitAmps);
}
// Update Consumption
limitSiteAreaWatts = limitSiteAreaWatts ? limitSiteAreaWatts : limitChargingStationsWatts;

MODIFY
src/migration/tasks/UpdateLimitsInConsumptionsTask.ts
src/migration/tasks/UpdateLimitsInConsumptionsTask.ts
@@ -34,12 +34,13 @@ export default class UpdateLimitsInConsumptionsTask extends MigrationTask {
if (chargingStation.chargePoints) {
const chargePoint = Utils.getChargePointFromID(chargingStation, connector.chargePointID);
limitAmps = Utils.getChargingStationAmperage(chargingStation, chargePoint, connector.connectorId);
+ limitWatts = Utils.convertAmpToWatt(chargingStation, chargePoint, connector.connectorId, limitAmps);
// Amps from connector
} else if (connector.amperage) {
limitAmps = connector.amperage;
+ limitWatts = Utils.convertAmpToWatt(chargingStation, null, connector.connectorId, limitAmps);
}
if (limitAmps) {
- limitWatts = Utils.convertAmpToWatt(chargingStation, connector.connectorId, limitAmps);
// Update
result = await global.database.getCollection(tenant.id, 'consumptions').updateMany(
{

MODIFY
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/OCPIMapping.ts
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/OCPIMapping.ts
@@ -431,7 +431,7 @@ export default class OCPIMapping {
if (connector.chargePointID) {
chargePoint = Utils.getChargePointFromID(chargingStation, connector.chargePointID);
}
- const voltage = Utils.getChargingStationVoltage(chargingStation, connector.connectorId);
+ const voltage = Utils.getChargingStationVoltage(chargingStation, chargePoint, connector.connectorId);
const amperage = Utils.getChargingStationAmperage(chargingStation, chargePoint, connector.connectorId);
const numberOfConnectedPhase = Utils.getNumberOfConnectedPhases(chargingStation, chargePoint, connector.connectorId);
return {

MODIFY
src/server/ocpp/services/OCPPService.ts
src/server/ocpp/services/OCPPService.ts
@@ -876,7 +876,7 @@ export default class OCPPService {
private async updateConnectorStatus(tenantID: string, chargingStation: ChargingStation, statusNotification: OCPPStatusNotificationRequestExtended, bothConnectorsUpdated) {
// Get it
let foundConnector: Connector = Utils.getConnectorFromID(chargingStation, statusNotification.connectorId);
- const oldConnectorStatus = foundConnector.status;
+ const oldConnectorStatus = foundConnector ? foundConnector.status : null;
if (!foundConnector) {
// Does not exist: Create
foundConnector = {
@@ -942,7 +942,8 @@ export default class OCPPService {
// Save
await ChargingStationStorage.saveChargingStation(tenantID, chargingStation);
// Start Transaction in OCPP: trigger Smart Charging
- if ((statusNotification.status === ChargePointStatus.CHARGING ||
+ if (oldConnectorStatus &&
+ (statusNotification.status === ChargePointStatus.CHARGING ||
statusNotification.status === ChargePointStatus.SUSPENDED_EV ||
statusNotification.status === ChargePointStatus.SUSPENDED_EVSE) &&
(oldConnectorStatus === ChargePointStatus.PREPARING ||

MODIFY
src/utils/Utils.ts
src/utils/Utils.ts
@@ -138,6 +138,10 @@ export default class Utils {
return InactivityStatus.ERROR;
}
+ public static getRoundedNumberToTwoDecimals(numberToRound: number): number {
+ return Math.round(numberToRound * 100) / 100;
+ }
+
public static objectHasProperty(object: object, key: string): boolean {
return _.has(object, key);
}
@@ -489,18 +493,17 @@ export default class Utils {
return userID;
}
-
- public static convertAmpToWatt(chargingStation: ChargingStation, connectorID = 0, ampValue: number): number {
- const voltage = Utils.getChargingStationVoltage(chargingStation, connectorID);
- if (voltage > 0) {
+ public static convertAmpToWatt(chargingStation: ChargingStation, chargePoint: ChargePoint, connectorID = 0, ampValue: number): number {
+ const voltage = Utils.getChargingStationVoltage(chargingStation, chargePoint, connectorID);
+ if (voltage) {
return voltage * ampValue;
}
return 0;
}
- public static convertWattToAmp(chargingStation: ChargingStation, connectorID = 0, wattValue: number): number {
- const voltage = Utils.getChargingStationVoltage(chargingStation, connectorID);
- if (voltage > 0) {
+ public static convertWattToAmp(chargingStation: ChargingStation, chargePoint: ChargePoint, connectorID = 0, wattValue: number): number {
+ const voltage = Utils.getChargingStationVoltage(chargingStation, chargePoint, connectorID);
+ if (voltage) {
return Math.floor(wattValue / voltage);
}
return 0;
@@ -537,43 +540,21 @@ export default class Utils {
}
}
if (totalAmps === 0 && chargingStation.maximumPower) {
- totalAmps = Utils.convertWattToAmp(chargingStation, 0, chargingStation.maximumPower);
+ totalAmps = Utils.convertWattToAmp(chargingStation, null, 0, chargingStation.maximumPower);
}
return totalAmps;
}
- public static getChargingStationPower(chargingStation: ChargingStation, connectorId = 0): number {
- if (chargingStation) {
- // Check at charging station level
- if (connectorId === 0 && chargingStation.maximumPower) {
- return chargingStation.maximumPower;
- }
- // Check at charge point level
- if (chargingStation.chargePoints) {
- for (const chargePoint of chargingStation.chargePoints) {
- if (chargePoint.connectorIDs.includes(connectorId) && chargePoint.power &&
- (chargePoint.cannotChargeInParallel || chargePoint.sharePowerToAllConnectors)) {
- return chargePoint.power;
- }
- }
- }
- // Check at connector level
- const connector = Utils.getConnectorFromID(chargingStation, connectorId);
- if (connector && connector.power) {
- return connector.power;
- }
- }
- return 0;
+ public static getChargingStationPower(chargingStation: ChargingStation, chargePoint: ChargePoint, connectorId = 0): number {
+ const amperage = Utils.getChargingStationAmperage(chargingStation, chargePoint, connectorId);
+ const voltage = Utils.getChargingStationVoltage(chargingStation, chargePoint, connectorId);
+ return voltage * amperage;
}
- public static getRoundedNumberToTwoDecimals(numberToRound: number): number {
- return Math.round(numberToRound * 100) / 100;
- }
-
- public static getNumberOfConnectedPhases(chargingStation: ChargingStation,
- chargePoint?: ChargePoint, connectorId = 0): number {
+ public static getNumberOfConnectedPhases(chargingStation: ChargingStation, chargePoint?: ChargePoint, connectorId = 0): number {
if (chargingStation) {
// Check at charge point level
+ if (chargingStation.chargePoints) {
if (chargePoint) {
if (connectorId === 0 && chargePoint.numberOfConnectedPhase) {
return chargePoint.numberOfConnectedPhase;
@@ -581,6 +562,17 @@ export default class Utils {
if (chargePoint.connectorIDs.includes(connectorId) && chargePoint.numberOfConnectedPhase) {
return chargePoint.numberOfConnectedPhase;
}
+ } else {
+ for (const chargePointOfCS of chargingStation.chargePoints) {
+ // Charging Station
+ if (connectorId === 0 && chargePointOfCS.numberOfConnectedPhase) {
+ return chargePointOfCS.numberOfConnectedPhase;
+ // Connector
+ } else if (chargePointOfCS.connectorIDs.includes(connectorId) && chargePointOfCS.numberOfConnectedPhase) {
+ return chargePointOfCS.numberOfConnectedPhase;
+ }
+ }
+ }
}
// Check at connector level
if (chargingStation.connectors) {
@@ -598,7 +590,7 @@ export default class Utils {
return 1;
}
- public static getChargingStationVoltage(chargingStation: ChargingStation, connectorId = 0): number {
+ public static getChargingStationVoltage(chargingStation: ChargingStation, chargePoint?: ChargePoint, connectorId = 0): number {
if (chargingStation) {
// Check at charging station level
if (chargingStation.voltage) {
@@ -606,14 +598,20 @@ export default class Utils {
}
// Check at charge point level
if (chargingStation.chargePoints) {
- for (const chargePoint of chargingStation.chargePoints) {
- // Take the first
- if (connectorId === 0 && chargePoint.voltage) {
- return chargePoint.voltage;
- }
+ if (chargePoint) {
if (chargePoint.connectorIDs.includes(connectorId) && chargePoint.voltage) {
return chargePoint.voltage;
}
+ } else {
+ for (const chargePointOfCS of chargingStation.chargePoints) {
+ // Charging Station
+ if (connectorId === 0 && chargePointOfCS.voltage) {
+ return chargePointOfCS.voltage;
+ // Connector
+ } else if (chargePointOfCS.connectorIDs.includes(connectorId) && chargePointOfCS.voltage) {
+ return chargePointOfCS.voltage;
+ }
+ }
}
}
// Check at connector level
@@ -632,18 +630,24 @@ export default class Utils {
return 0;
}
- public static getChargingStationCurrentType(chargingStation: ChargingStation, connectorId = 0): CurrentType {
+ public static getChargingStationCurrentType(chargingStation: ChargingStation, chargePoint: ChargePoint, connectorId = 0): CurrentType {
if (chargingStation) {
// Check at charge point level
if (chargingStation.chargePoints) {
- for (const chargePoint of chargingStation.chargePoints) {
- // Take the first
- if (connectorId === 0 && chargePoint.currentType) {
- return chargePoint.currentType;
- }
+ if (chargePoint) {
if (chargePoint.connectorIDs.includes(connectorId) && chargePoint.currentType) {
return chargePoint.currentType;
}
+ } else {
+ for (const chargePointOfCS of chargingStation.chargePoints) {
+ // Charging Station
+ if (connectorId === 0 && chargePointOfCS.currentType) {
+ return chargePointOfCS.currentType;
+ // Connector
+ } else if (chargePointOfCS.connectorIDs.includes(connectorId) && chargePointOfCS.currentType) {
+ return chargePointOfCS.currentType;
+ }
+ }
}
}
// Check at connector level
@@ -663,8 +667,7 @@ export default class Utils {
}
// Tslint:disable-next-line: cyclomatic-complexity
- public static getChargingStationAmperage(chargingStation: ChargingStation,
- chargePoint?: ChargePoint, connectorId = 0): number {
+ public static getChargingStationAmperage(chargingStation: ChargingStation, chargePoint?: ChargePoint, connectorId = 0): number {
let totalAmps = 0;
if (chargingStation) {
// Check at charge point level
@@ -706,8 +709,7 @@ export default class Utils {
return totalAmps;
}
- public static getChargingStationAmperageLimit(chargingStation: ChargingStation,
- chargePoint: ChargePoint, connectorId = 0): number {
+ public static getChargingStationAmperageLimit(chargingStation: ChargingStation, chargePoint: ChargePoint, connectorId = 0): number {
let amperageLimit = 0;
if (chargingStation) {
if (connectorId > 0) {

MODIFY
test/api/context/TenantContext.ts
test/api/context/TenantContext.ts
@@ -267,21 +267,34 @@ export default class TenantContext {
// Charging Station
expect(createdChargingStation.voltage).to.eql(230);
// Connectors
- expect(createdChargingStation.connectors.length).to.eql(2);
- expect(createdChargingStation.connectors[0].power).to.eql(22080);
- expect(createdChargingStation.connectors[0].amperage).to.eql(96);
- expect(createdChargingStation.connectors[0].type).to.eql('T2');
- expect(createdChargingStation.connectors[1].power).to.eql(22080);
- expect(createdChargingStation.connectors[1].amperage).to.eql(96);
- expect(createdChargingStation.connectors[1].type).to.eql('T2');
+ expect(createdChargingStation.connectors.length).to.eql(2,
+ `Number of connector of charging station ${createdChargingStation.id} must be 2`);
+ expect(createdChargingStation.connectors[0].power).to.eql(22080,
+ `Connector ID 1 of charging station ${createdChargingStation.id} must have 22080 W`);
+ expect(createdChargingStation.connectors[0].amperage).to.eql(96,
+ `Connector ID 1 of charging station ${createdChargingStation.id} must have 96 A`);
+ expect(createdChargingStation.connectors[0].type).to.eql('T2',
+ `Connector ID 1 of charging station ${createdChargingStation.id} must have Type 2 connector`);
+ expect(createdChargingStation.connectors[1].power).to.eql(22080,
+ `Connector ID 2 of charging station ${createdChargingStation.id} must have 22080 W`);
+ expect(createdChargingStation.connectors[1].amperage).to.eql(96,
+ `Connector ID 2 of charging station ${createdChargingStation.id} must have 96 A`);
+ expect(createdChargingStation.connectors[1].type).to.eql('T2',
+ `Connector ID 2 of charging station ${createdChargingStation.id} must have Type 2 connector`);
// Charge Points
- expect(createdChargingStation.chargePoints.length).to.eql(1);
+ expect(createdChargingStation.chargePoints.length).to.eql(1,
+ `Number of charge point of charging station ${createdChargingStation.id} must be 1`);
expect(createdChargingStation.chargePoints[0].currentType).to.eql('AC');
- expect(createdChargingStation.chargePoints[0].numberOfConnectedPhase).to.eql(3);
- expect(createdChargingStation.chargePoints[0].cannotChargeInParallel).to.eql(false);
- expect(createdChargingStation.chargePoints[0].sharePowerToAllConnectors).to.eql(false);
- expect(createdChargingStation.chargePoints[0].excludeFromPowerLimitation).to.eql(false);
- expect(createdChargingStation.chargePoints[0].ocppParamForPowerLimitation).to.eql('maxintensitysocket');
+ expect(createdChargingStation.chargePoints[0].numberOfConnectedPhase).to.eql(3,
+ `Charge Point ID 1 of charging station ${createdChargingStation.id} must have 3 phases`);
+ expect(createdChargingStation.chargePoints[0].cannotChargeInParallel).to.eql(false,
+ `Charge Point ID 1 of charging station ${createdChargingStation.id} cannot charge in parallel`);
+ expect(createdChargingStation.chargePoints[0].sharePowerToAllConnectors).to.eql(false,
+ `Charge Point ID 1 of charging station ${createdChargingStation.id} cannot share power`);
+ expect(createdChargingStation.chargePoints[0].excludeFromPowerLimitation).to.eql(false,
+ `Charge Point ID 1 of charging station ${createdChargingStation.id} cannot be excluded from power limitation`);
+ expect(createdChargingStation.chargePoints[0].ocppParamForPowerLimitation).to.eql('maxintensitysocket',
+ `Charge Point ID 1 of charging station ${createdChargingStation.id} must have OCPP param 'maxintensitysocket'`);
// Assign to Site Area
if (siteArea) {
createdChargingStation.siteAreaID = siteArea.id;

Added charge points in utils methods