Handle charge point
MODIFY
src/migration/tasks/UpdateChargingStationTemplatesTask.ts
src/migration/tasks/UpdateChargingStationTemplatesTask.ts
@@ -147,7 +147,7 @@ export default class UpdateChargingStationTemplatesTask extends MigrationTask {
private async removeChargingStationUnusedPropsInDB(tenant: Tenant) {
const result = await global.database.getCollection<any>(tenant.id, 'chargingstations').updateMany(
- { 'ocppAdvancedCommands': { $exists: true } },
+ { },
{
$unset: {
'numberOfConnectedPhase': '',

MODIFY
src/server/rest/service/ChargingStationService.ts
src/server/rest/service/ChargingStationService.ts
-import fs from 'fs';
-
+import { Action, Entity } from '../../../types/Authorization';
+import ChargingStation, { Command, OCPPParams, StaticLimitAmps } from '../../../types/ChargingStation';
+import { HTTPAuthError, HTTPError } from '../../../types/HTTPError';
+import { HttpChargingStationCommandRequest, HttpIsAuthorizedRequest } from '../../../types/requests/HttpChargingStationRequest';
import { NextFunction, Request, Response } from 'express';
-import sanitize from 'mongo-sanitize';
+import { OCPPConfigurationStatus, OCPPStatus } from '../../../types/ocpp/OCPPClient';
-import Authorizations from '../../../authorization/Authorizations';
-import ChargingStationClientFactory from '../../../client/ocpp/ChargingStationClientFactory';
import AppAuthError from '../../../exception/AppAuthError';
import AppError from '../../../exception/AppError';
+import Authorizations from '../../../authorization/Authorizations';
import BackendError from '../../../exception/BackendError';
+import { ChargingProfile } from '../../../types/ChargingProfile';
+import ChargingStationClientFactory from '../../../client/ocpp/ChargingStationClientFactory';
+import { ChargingStationInErrorType } from '../../../types/InError';
+import ChargingStationSecurity from './security/ChargingStationSecurity';
+import ChargingStationStorage from '../../../storage/mongodb/ChargingStationStorage';
import ChargingStationVendorFactory from '../../../integration/charging-station-vendor/ChargingStationVendorFactory';
-import SmartChargingFactory from '../../../integration/smart-charging/SmartChargingFactory';
+import Constants from '../../../utils/Constants';
+import { DataResult } from '../../../types/DataResult';
+import I18nManager from '../../../utils/I18nManager';
import LockingHelper from '../../../locking/LockingHelper';
import LockingManager from '../../../locking/LockingManager';
-import ChargingStationStorage from '../../../storage/mongodb/ChargingStationStorage';
+import Logging from '../../../utils/Logging';
import OCPPStorage from '../../../storage/mongodb/OCPPStorage';
-import SiteAreaStorage from '../../../storage/mongodb/SiteAreaStorage';
-import SiteStorage from '../../../storage/mongodb/SiteStorage';
-import TransactionStorage from '../../../storage/mongodb/TransactionStorage';
-import { Action, Entity } from '../../../types/Authorization';
-import { ChargingProfile } from '../../../types/ChargingProfile';
-import ChargingStation, { Command, OCPPParams, StaticLimitAmps } from '../../../types/ChargingStation';
-import { DataResult } from '../../../types/DataResult';
-import { HTTPAuthError, HTTPError } from '../../../types/HTTPError';
-import { ChargingStationInErrorType } from '../../../types/InError';
-import { OCPPConfigurationStatus, OCPPStatus } from '../../../types/ocpp/OCPPClient';
-import { HttpChargingStationCommandRequest, HttpIsAuthorizedRequest } from '../../../types/requests/HttpChargingStationRequest';
+import OCPPUtils from '../../ocpp/utils/OCPPUtils';
import { ServerAction } from '../../../types/Server';
import SiteArea from '../../../types/SiteArea';
+import SiteAreaStorage from '../../../storage/mongodb/SiteAreaStorage';
+import SiteStorage from '../../../storage/mongodb/SiteStorage';
+import SmartChargingFactory from '../../../integration/smart-charging/SmartChargingFactory';
import TenantComponents from '../../../types/TenantComponents';
+import TransactionStorage from '../../../storage/mongodb/TransactionStorage';
import UserToken from '../../../types/UserToken';
-import Constants from '../../../utils/Constants';
-import I18nManager from '../../../utils/I18nManager';
-import Logging from '../../../utils/Logging';
import Utils from '../../../utils/Utils';
-import OCPPUtils from '../../ocpp/utils/OCPPUtils';
-import ChargingStationSecurity from './security/ChargingStationSecurity';
import UtilsService from './UtilsService';
+import fs from 'fs';
+import sanitize from 'mongo-sanitize';
const MODULE_NAME = 'ChargingStationService';
@@ -190,9 +189,9 @@ export default class ChargingStationService {
sanitize(filteredRequest.coordinates[1])
];
}
+ // No charge point
+ if (!chargingStation.chargePoints && filteredRequest.connectors) {
// Update Connectors
- if (filteredRequest.connectors) {
- // Assign to Charging Station's connector
for (const filteredConnector of filteredRequest.connectors) {
// Set
chargingStation.connectors[filteredConnector.connectorId - 1].type = filteredConnector.type;

MODIFY
src/storage/mongodb/ChargingStationStorage.ts
src/storage/mongodb/ChargingStationStorage.ts
@@ -430,7 +430,7 @@ export default class ChargingStationStorage {
for (const connector of chargingStationToSave.connectors) {
if (connector) {
connector.connectorId = Utils.convertToInt(connector.connectorId);
- connector.power = Utils.convertToInt(connector.power);
+ connector.power = connector.power ? Utils.convertToInt(connector.power) : null;
connector.amperage = connector.amperage ? Utils.convertToInt(connector.amperage) : null;
connector.voltage = connector.voltage ? Utils.convertToInt(connector.voltage) : null;
connector.chargePointID = connector.chargePointID ? Utils.convertToInt(connector.chargePointID) : null;
@@ -447,14 +447,14 @@ export default class ChargingStationStorage {
if (chargingStationToSave.chargePoints && Array.isArray(chargingStationToSave.chargePoints)) {
for (const chargePoint of chargingStationToSave.chargePoints) {
if (chargePoint) {
- chargePoint.voltage = Utils.convertToInt(chargePoint.voltage);
- chargePoint.amperage = Utils.convertToInt(chargePoint.amperage);
- chargePoint.numberOfConnectedPhase = Utils.convertToInt(chargePoint.numberOfConnectedPhase);
+ chargePoint.voltage = chargePoint.voltage ? Utils.convertToInt(chargePoint.voltage) : null;
+ chargePoint.amperage = chargePoint.amperage ? Utils.convertToInt(chargePoint.amperage) : null;
+ chargePoint.numberOfConnectedPhase = chargePoint.numberOfConnectedPhase ? Utils.convertToInt(chargePoint.numberOfConnectedPhase) : null;
chargePoint.cannotChargeInParallel = Utils.convertToBoolean(chargePoint.cannotChargeInParallel);
chargePoint.sharePowerToAllConnectors = Utils.convertToBoolean(chargePoint.sharePowerToAllConnectors);
chargePoint.excludeFromPowerLimitation = Utils.convertToBoolean(chargePoint.excludeFromPowerLimitation);
- chargePoint.power = Utils.convertToInt(chargePoint.power);
- chargePoint.efficiency = Utils.convertToInt(chargePoint.efficiency);
+ chargePoint.power = chargePoint.power ? Utils.convertToInt(chargePoint.power) : null;
+ chargePoint.efficiency = chargePoint.efficiency ? Utils.convertToInt(chargePoint.efficiency) : null;
chargePoint.connectorIDs = chargePoint.connectorIDs.map((connectorID) => Utils.convertToInt(connectorID));
}
}

MODIFY
src/utils/Utils.ts
src/utils/Utils.ts
@@ -502,9 +502,57 @@ export default class Utils {
return 0;
}
+ public static computeChargingStationTotalAmps(chargingStation: ChargingStation): number {
+ let totalAmps = 0;
+ if (chargingStation) {
+ // Check at charge point level
+ if (chargingStation.chargePoints) {
+ for (const chargePoint of chargingStation.chargePoints) {
+ totalAmps += chargePoint.amperage;
+ }
+ }
+ // Check at connector level
+ if (totalAmps === 0) {
+ if (chargingStation.connectors) {
+ for (const connector of chargingStation.connectors) {
+ totalAmps += connector.amperage;
+ }
+ }
+ }
+ }
+ if (totalAmps === 0 && chargingStation.maximumPower > 0) {
+ totalAmps = Utils.convertWattToAmp(chargingStation, 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 > 0) {
+ return chargingStation.maximumPower;
+ }
+ // Check at charge point level
+ if (chargingStation.chargePoints) {
+ for (const chargePoint of chargingStation.chargePoints) {
+ if (chargePoint.connectorIDs.includes(connectorId) && chargePoint.power > 0 &&
+ (chargePoint.cannotChargeInParallel || chargePoint.sharePowerToAllConnectors)) {
+ return chargePoint.power;
+ }
+ }
+ }
+ // Check at connector level
+ if (chargingStation.connectors && chargingStation.connectors[connectorId - 1] &&
+ chargingStation.connectors[connectorId - 1].power > 0) {
+ return chargingStation.connectors[connectorId - 1].power;
+ }
+ }
+ return 0;
+ }
+
public static getChargingStationNumberOfConnectedPhases(chargingStation: ChargingStation, connectorId = 0): number {
if (chargingStation) {
- // Check phase at charge point level
+ // Check at charge point level
if (chargingStation.chargePoints) {
for (const chargePoint of chargingStation.chargePoints) {
// Take the first
@@ -516,7 +564,7 @@ export default class Utils {
}
}
}
- // Check phases at connector level
+ // Check at connector level
if (chargingStation.connectors) {
for (const connector of chargingStation.connectors) {
// Take the first
@@ -532,13 +580,44 @@ export default class Utils {
return 1;
}
+ public static getChargingStationAmperage(chargingStation: ChargingStation, connectorId = 0): number {
+ if (chargingStation) {
+ // Check at charge point level
+ if (chargingStation.chargePoints) {
+ for (const chargePoint of chargingStation.chargePoints) {
+ // Take the first
+ if (connectorId === 0 && chargePoint.amperage) {
+ return chargePoint.amperage;
+ }
+ if (chargePoint.connectorIDs.includes(connectorId) && chargePoint.amperage &&
+ (chargePoint.cannotChargeInParallel || chargePoint.sharePowerToAllConnectors)) {
+ return chargePoint.amperage;
+ }
+ }
+ }
+ // Check at connector level
+ if (chargingStation.connectors) {
+ for (const connector of chargingStation.connectors) {
+ // Take the first
+ if (connectorId === 0 && connector.amperage) {
+ return connector.amperage;
+ }
+ if (connector.connectorId === connectorId && connector.amperage) {
+ return connector.amperage;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
public static getChargingStationVoltage(chargingStation: ChargingStation, connectorId = 0): number {
if (chargingStation) {
- // Check voltage at charging station level
+ // Check at charging station level
if (chargingStation.voltage > 0) {
return chargingStation.voltage;
}
- // Check voltage at charge point level
+ // Check at charge point level
if (chargingStation.chargePoints) {
for (const chargePoint of chargingStation.chargePoints) {
// Take the first
@@ -550,7 +629,7 @@ export default class Utils {
}
}
}
- // Check voltage at connector level
+ // Check at connector level
if (chargingStation.connectors) {
for (const connector of chargingStation.connectors) {
// Take the first
@@ -568,7 +647,7 @@ export default class Utils {
public static getChargingStationCurrentType(chargingStation: ChargingStation, connectorId = 0): CurrentType {
if (chargingStation) {
- // Check voltage at charge point level
+ // Check at charge point level
if (chargingStation.chargePoints) {
for (const chargePoint of chargingStation.chargePoints) {
// Take the first
@@ -580,7 +659,7 @@ export default class Utils {
}
}
}
- // Check voltage at connector level
+ // Check at connector level
if (chargingStation.connectors) {
for (const connector of chargingStation.connectors) {
// Take the first

Handle charge point