Migration of amp limit per connector
MODIFY
src/integration/charging-station-vendor/ChargingStationVendorIntegration.ts
src/integration/charging-station-vendor/ChargingStationVendorIntegration.ts
@@ -109,7 +109,7 @@ export default abstract class ChargingStationVendorIntegration {
source: chargingStation.id,
action: ServerAction.CHARGING_STATION_LIMIT_POWER,
module: MODULE_NAME, method: 'setStaticPowerLimitation',
- message: 'Charging Station does not support static power limitation'
+ message: 'Charging Station capabilities does not support static power limitation'
});
}
if (maxAmps < StaticLimitAmps.MIN_LIMIT) {
@@ -202,7 +202,7 @@ export default abstract class ChargingStationVendorIntegration {
if (ocppParamName === chargePoint.ocppParamForPowerLimitation) {
// Update the connector limit amps
for (const connectorID of chargePoint.connectorIDs) {
- const connector = Utils.getChargingStationConnectorFromID(chargingStation, connectorID);
+ const connector = Utils.getConnectorFromID(chargingStation, connectorID);
connector.amperageLimit = this.convertLimitAmpToAllPhases(
chargingStation, chargePoint, connectorID, Utils.convertToInt(ocppParamValue));
Logging.logInfo({
@@ -589,8 +589,8 @@ export default abstract class ChargingStationVendorIntegration {
detailedMessages: { connectorID }
});
// Default
- const limitDefaultMaxAmps = Utils.getChargingStationConnectorFromID(chargingStation, connectorID).amperageLimit;
- const limitDefaultMaxPower = Utils.getChargingStationConnectorFromID(chargingStation, connectorID).power;
+ const limitDefaultMaxAmps = Utils.getConnectorFromID(chargingStation, connectorID).amperageLimit;
+ const limitDefaultMaxPower = Utils.getConnectorFromID(chargingStation, connectorID).power;
// Should fail safe!
try {
if (connectorID === 0) {

MODIFY
src/locking/LockingManager.ts
src/locking/LockingManager.ts
@@ -51,6 +51,7 @@ export default class LockingManager {
message: `Cannot acquire the lock entity '${lock.entity}' ('${lock.key}') of type '${lock.type}'`,
detailedMessages: { lock, error: error.message, stack: error.stack }
});
+ console.log(`Cannot acquire the lock entity '${lock.entity}' ('${lock.key}') of type '${lock.type}'`);
return false;
}
}

MODIFY
src/migration/tasks/UpdateChargingStationTemplatesTask.ts
src/migration/tasks/UpdateChargingStationTemplatesTask.ts
import ChargingStationStorage from '../../storage/mongodb/ChargingStationStorage';
+import ChargingStationVendorFactory from '../../integration/charging-station-vendor/ChargingStationVendorFactory';
import Constants from '../../utils/Constants';
import Logging from '../../utils/Logging';
import MigrationTask from '../MigrationTask';
@@ -32,11 +33,13 @@ export default class UpdateChargingStationTemplatesTask extends MigrationTask {
await this.applyTemplateToChargingStations(tenant);
// Remove unused props
await this.cleanUpChargingStationDBProps(tenant);
+ // Initialize amperage limitation
+ await this.initChargingStationLimitAmps(tenant);
}
}
getVersion() {
- return '1.89997';
+ return '1.899991';
}
private async applyTemplateToChargingStations(tenant: Tenant) {
@@ -103,6 +106,84 @@ export default class UpdateChargingStationTemplatesTask extends MigrationTask {
}
}
+ private async initChargingStationLimitAmps(tenant: Tenant) {
+ let updated = 0;
+ // Get the charging stations
+ const chargingStations = await ChargingStationStorage.getChargingStations(tenant.id, {
+ issuer: true
+ }, Constants.DB_PARAMS_MAX_LIMIT);
+ // Update
+ for (const chargingStation of chargingStations.result) {
+ // Check Charge Point
+ if (chargingStation.chargePoints) {
+ for (const chargePoint of chargingStation.chargePoints) {
+ let chargePointUpdated = false;
+ // Get the Vendor instance
+ const chargingStationVendor = ChargingStationVendorFactory.getChargingStationVendorImpl(chargingStation);
+ if (chargingStationVendor) {
+ // Get max charge point amps
+ const amperageChargePointMax = Utils.getChargingStationAmperage(chargingStation, chargePoint);
+ try {
+ // Call the limitation
+ const result = await chargingStationVendor.setStaticPowerLimitation(tenant.id, chargingStation,
+ chargePoint, amperageChargePointMax);
+ if (result.status === OCPPConfigurationStatus.ACCEPTED || result.status === OCPPConfigurationStatus.REBOOT_REQUIRED) {
+ chargePointUpdated = true;
+ updated++;
+ } else {
+ Logging.logError({
+ tenantID: tenant.id,
+ action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE,
+ module: MODULE_NAME, method: 'initChargingStationLimitAmps',
+ message: `Cannot set Charge Point static limitation to ${amperageChargePointMax}A`,
+ detailedMessages: { chargePoint }
+ });
+ }
+ } catch (error) {
+ Logging.logError({
+ tenantID: tenant.id,
+ action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE,
+ module: MODULE_NAME, method: 'initChargingStationLimitAmps',
+ message: `Cannot set Charge Point static limitation to ${amperageChargePointMax}A`,
+ detailedMessages: { error: error.message, stack: error.stack, chargePoint }
+ });
+ }
+ }
+ if (!chargePointUpdated) {
+ // Update each connector manually
+ for (const connectorID of chargePoint.connectorIDs) {
+ // Get max connector amps
+ const connector = Utils.getConnectorFromID(chargingStation, connectorID);
+ if (connector) {
+ const amperageConnectorMax = Utils.getChargingStationAmperage(chargingStation, chargePoint, connectorID);
+ connector.amperageLimit = amperageConnectorMax;
+ }
+ }
+ await ChargingStationStorage.saveChargingStation(tenant.id, chargingStation);
+ updated++;
+ }
+ }
+ } else if (chargingStation.connectors) {
+ // Update each connector manually
+ for (const connector of chargingStation.connectors) {
+ if (connector) {
+ connector.amperageLimit = connector.amperage;
+ }
+ }
+ await ChargingStationStorage.saveChargingStation(tenant.id, chargingStation);
+ updated++;
+ }
+ }
+ if (updated > 0) {
+ Logging.logDebug({
+ tenantID: tenant.id,
+ action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE,
+ module: MODULE_NAME, method: 'cleanUpChargingStationDBProps',
+ message: `${updated} Charging Stations amperage limit has been updated in Tenant '${tenant.name}'`
+ });
+ }
+ }
+
private async updateChargingStationTemplate() {
// Update current Chargers
ChargingStationStorage.updateChargingStationTemplatesFromFile().catch(

MODIFY
src/server/ocpp/services/OCPPService.ts
src/server/ocpp/services/OCPPService.ts
@@ -1180,8 +1180,8 @@ export default class OCPPService {
const chargingStationVendor = ChargingStationVendorFactory.getChargingStationVendorImpl(chargingStation);
if (chargingStationVendor) {
// Get current limitation
- const connector = Utils.getChargingStationConnectorFromID(chargingStation, transaction.connectorId);
- const chargePoint = Utils.getChargingStationChargePointFromID(chargingStation, connector.chargePointID);
+ const connector = Utils.getConnectorFromID(chargingStation, transaction.connectorId);
+ const chargePoint = Utils.getChargePointFromID(chargingStation, connector.chargePointID);
const connectorLimit = await chargingStationVendor.getCurrentConnectorLimit(
tenantID, chargingStation, chargePoint, transaction.connectorId);
consumption.limitAmps = connectorLimit.limitAmps;
@@ -1189,7 +1189,7 @@ export default class OCPPService {
consumption.limitSource = connectorLimit.limitSource;
} else {
// Default
- const connector = Utils.getChargingStationConnectorFromID(chargingStation, transaction.connectorId);
+ const connector = Utils.getConnectorFromID(chargingStation, transaction.connectorId);
consumption.limitAmps = connector.amperageLimit;
consumption.limitWatts = connector.power;
consumption.limitSource = ConnectorCurrentLimitSource.CONNECTOR;

MODIFY
src/server/ocpp/utils/OCPPUtils.ts
src/server/ocpp/utils/OCPPUtils.ts
@@ -425,7 +425,7 @@ export default class OCPPUtils {
});
}
// Get charge point
- const chargePoint = Utils.getChargingStationChargePointFromID(chargingStation, chargingProfile.chargePointID);
+ const chargePoint = Utils.getChargePointFromID(chargingStation, chargingProfile.chargePointID);
// Get Vendor Instance
const chargingStationVendor = ChargingStationVendorFactory.getChargingStationVendorImpl(chargingStation);
if (!chargingStationVendor) {

MODIFY
src/server/rest/service/ChargingStationService.ts
src/server/rest/service/ChargingStationService.ts
@@ -200,7 +200,7 @@ export default class ChargingStationService {
// Update Connectors
for (const filteredConnector of filteredRequest.connectors) {
// Set
- const connector = Utils.getChargingStationConnectorFromID(chargingStation, filteredConnector.connectorId);
+ const connector = Utils.getConnectorFromID(chargingStation, filteredConnector.connectorId);
connector.type = filteredConnector.type;
connector.power = filteredConnector.power;
connector.amperage = filteredConnector.amperage;
@@ -258,7 +258,7 @@ export default class ChargingStationService {
const chargingStation = await ChargingStationStorage.getChargingStation(req.user.tenantID, filteredRequest.chargeBoxID);
UtilsService.assertObjectExists(action, chargingStation, `Charging Station '${filteredRequest.chargeBoxID}' doesn't exist.`,
MODULE_NAME, 'handleChargingStationLimitPower', req.user);
- const chargePoint = Utils.getChargingStationChargePointFromID(chargingStation, filteredRequest.chargePointID);
+ const chargePoint = Utils.getChargePointFromID(chargingStation, filteredRequest.chargePointID);
UtilsService.assertObjectExists(action, chargePoint, `Charge Point '${filteredRequest.chargePointID}' doesn't exist.`,
MODULE_NAME, 'handleChargingStationLimitPower', req.user);
let siteID = null;
@@ -469,7 +469,7 @@ export default class ChargingStationService {
const chargingStation = await ChargingStationStorage.getChargingStation(req.user.tenantID, filteredRequest.chargingStationID);
UtilsService.assertObjectExists(action, chargingStation, `ChargingStation '${req.body.ChargingStationID}' doesn't exist.`,
MODULE_NAME, 'handleUpdateChargingProfile', req.user);
- const chargePoint = Utils.getChargingStationChargePointFromID(chargingStation, filteredRequest.chargePointID);
+ const chargePoint = Utils.getChargePointFromID(chargingStation, filteredRequest.chargePointID);
UtilsService.assertObjectExists(action, chargePoint, `Charge Point '${filteredRequest.chargePointID}' doesn't exist.`,
MODULE_NAME, 'handleUpdateChargingProfile', req.user);
// Check Mandatory fields
@@ -1067,8 +1067,8 @@ export default class ChargingStationService {
});
}
// Get composite schedule
- const connector = Utils.getChargingStationConnectorFromID(chargingStation, filteredRequest.args.connectorId);
- const chargePoint = Utils.getChargingStationChargePointFromID(chargingStation, connector.chargePointID);
+ const connector = Utils.getConnectorFromID(chargingStation, filteredRequest.args.connectorId);
+ const chargePoint = Utils.getChargePointFromID(chargingStation, connector.chargePointID);
result = await chargingStationVendor.getCompositeSchedule(
req.user.tenantID, chargingStation, chargePoint, filteredRequest.args.connectorId, filteredRequest.args.duration);
} else {

MODIFY
src/utils/Utils.ts
src/utils/Utils.ts
@@ -51,7 +51,7 @@ export default class Utils {
if (!chargingStation || !chargingStation.connectors) {
return 0;
}
- const connector = Utils.getChargingStationConnectorFromID(chargingStation, connectorId);
+ const connector = Utils.getConnectorFromID(chargingStation, connectorId);
if (connector.power <= 3680) {
// Notify every 120 mins
intervalMins = 120;
@@ -241,7 +241,7 @@ export default class Utils {
let lockAllConnectors = false;
// Check
for (const connectorID of chargePoint.connectorIDs) {
- const connector = Utils.getChargingStationConnectorFromID(chargingStation, connectorID);
+ const connector = Utils.getConnectorFromID(chargingStation, connectorID);
if (!connector) {
continue;
}
@@ -253,7 +253,7 @@ export default class Utils {
// Lock?
if (lockAllConnectors) {
for (const connectorID of chargePoint.connectorIDs) {
- const connector = Utils.getChargingStationConnectorFromID(chargingStation, connectorID);
+ const connector = Utils.getConnectorFromID(chargingStation, connectorID);
if (!connector) {
continue;
}
@@ -495,14 +495,14 @@ export default class Utils {
return 0;
}
- public static getChargingStationChargePointFromID(chargingStation: ChargingStation, chargePointID: number): ChargePoint {
+ public static getChargePointFromID(chargingStation: ChargingStation, chargePointID: number): ChargePoint {
if (!chargingStation.chargePoints) {
return null;
}
return chargingStation.chargePoints.find((chargePoint) => chargePoint.chargePointID === chargePointID);
}
- public static getChargingStationConnectorFromID(chargingStation: ChargingStation, connectorID: number): Connector {
+ public static getConnectorFromID(chargingStation: ChargingStation, connectorID: number): Connector {
if (!chargingStation.connectors) {
return null;
}
@@ -547,7 +547,7 @@ export default class Utils {
}
}
// Check at connector level
- const connector = Utils.getChargingStationConnectorFromID(chargingStation, connectorId);
+ const connector = Utils.getConnectorFromID(chargingStation, connectorId);
if (connector && connector.power) {
return connector.power;
}
@@ -696,7 +696,7 @@ export default class Utils {
let amperageLimit = 0;
if (chargingStation) {
if (connectorId > 0) {
- return Utils.getChargingStationConnectorFromID(chargingStation, connectorId).amperageLimit;
+ return Utils.getConnectorFromID(chargingStation, connectorId).amperageLimit;
}
// Check at charge point level
if (chargingStation.chargePoints) {
@@ -706,11 +706,11 @@ export default class Utils {
}
// Add limit amp of one connector of the charge point
if (chargePoint.cannotChargeInParallel || chargePoint.sharePowerToAllConnectors) {
- return Utils.getChargingStationConnectorFromID(chargingStation, chargePoint.connectorIDs[0]).amperageLimit;
+ return Utils.getConnectorFromID(chargingStation, chargePoint.connectorIDs[0]).amperageLimit;
}
// Add limit amp of all connectors of the charge point
for (const connectorID of chargePoint.connectorIDs) {
- amperageLimit += Utils.getChargingStationConnectorFromID(chargingStation, connectorID).amperageLimit;
+ amperageLimit += Utils.getConnectorFromID(chargingStation, connectorID).amperageLimit;
}
} else {
for (const chargePointOfCS of chargingStation.chargePoints) {
@@ -720,11 +720,11 @@ export default class Utils {
if (chargePointOfCS.cannotChargeInParallel ||
chargePointOfCS.sharePowerToAllConnectors) {
// Add limit amp of one connector
- amperageLimit += Utils.getChargingStationConnectorFromID(chargingStation, chargePointOfCS.connectorIDs[0]).amperageLimit;
+ amperageLimit += Utils.getConnectorFromID(chargingStation, chargePointOfCS.connectorIDs[0]).amperageLimit;
} else {
// Add limit amp of all connectors
for (const connectorID of chargePointOfCS.connectorIDs) {
- amperageLimit += Utils.getChargingStationConnectorFromID(chargingStation, connectorID).amperageLimit;
+ amperageLimit += Utils.getConnectorFromID(chargingStation, connectorID).amperageLimit;
}
}
}

Migration of amp limit per connector