Added new migration task
MODIFY
src/migration/MigrationHandler.ts
src/migration/MigrationHandler.ts
@@ -23,6 +23,7 @@ import MigrationStorage from '../storage/mongodb/MigrationStorage';
import RenameTagPropertiesTask from './tasks/RenameTagPropertiesTask';
import { ServerAction } from '../types/Server';
import SiteUsersHashIDsTask from './tasks/SiteUsersHashIDsTask';
+import UpdateChargingStationStaticLimitationTask from './tasks/UpdateChargingStationStaticLimitationTask';
import UpdateChargingStationTemplatesTask from './tasks/UpdateChargingStationTemplatesTask';
import UpdateConsumptionsToObjectIDs from './tasks/UpdateConsumptionsToObjectIDs';
import cluster from 'cluster';
@@ -71,6 +72,7 @@ export default class MigrationHandler {
currentMigrationTasks.push(new UpdateConsumptionsToObjectIDs());
currentMigrationTasks.push(new AddSiteAreaLimitToConsumptionsTask());
currentMigrationTasks.push(new MigrateOcpiTransactionsTask());
+ currentMigrationTasks.push(new UpdateChargingStationStaticLimitationTask());
// Get the already done migrations from the DB
const migrationTasksDone = await MigrationStorage.getMigrations();
// Check

ADD
src/migration/tasks/UpdateChargingStationStaticLimitationTask.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';
+import { OCPPConfigurationStatus } from '../../types/ocpp/OCPPClient';
+import { ServerAction } from '../../types/Server';
+import Tenant from '../../types/Tenant';
+import TenantStorage from '../../storage/mongodb/TenantStorage';
+import Utils from '../../utils/Utils';
+
+const MODULE_NAME = 'UpdateChargingStationTemplatesTask';
+
+export default class UpdateChargingStationStaticLimitationTask extends MigrationTask {
+ isAsynchronous() {
+ return true;
+ }
+
+ getName() {
+ return 'UpdateChargingStationStaticLimitationTask';
+ }
+
+ async migrate() {
+ const tenants = await TenantStorage.getTenants({}, Constants.DB_PARAMS_MAX_LIMIT);
+ for (const tenant of tenants.result) {
+ // Initialize amperage limitation
+ await this.initChargingStationLimitAmps(tenant);
+ }
+ }
+
+ getVersion() {
+ return '1.0';
+ }
+
+ 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}'`
+ });
+ }
+ }
+}

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';
-import { OCPPConfigurationStatus } from '../../types/ocpp/OCPPClient';
import OCPPUtils from '../../server/ocpp/utils/OCPPUtils';
import { ServerAction } from '../../types/Server';
import Tenant from '../../types/Tenant';
@@ -30,11 +28,9 @@ export default class UpdateChargingStationTemplatesTask extends MigrationTask {
const tenants = await TenantStorage.getTenants({}, Constants.DB_PARAMS_MAX_LIMIT);
for (const tenant of tenants.result) {
// Update current Charging Station with Template
- // await this.applyTemplateToChargingStations(tenant);
+ await this.applyTemplateToChargingStations(tenant);
// Remove unused props
await this.cleanUpChargingStationDBProps(tenant);
- // Initialize amperage limitation
- // await this.initChargingStationLimitAmps(tenant);
}
}
@@ -106,84 +102,6 @@ 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(

Added new migration task