Removed non performant coding. Added PricingSource enum, add getChargingStationByOcpiLocationUid in storage (removed serialNumber). Removed deleteChargingStationBySerialNumber().
MODIFY
src/client/ocpi/EmspOCPIClient.ts
src/client/ocpi/EmspOCPIClient.ts
@@ -114,7 +114,7 @@ export default class EmspOCPIClient extends OCPIClient {
return result;
}
- public async getAndCheckCompany(): Promise<Company> {
+ public async checkAndGetCompany(): Promise<Company> {
let company = await CompanyStorage.getCompany(this.tenant.id, this.ocpiEndpoint.id);
if (!company) {
company = {
@@ -141,25 +141,21 @@ export default class EmspOCPIClient extends OCPIClient {
// Get locations endpoint url
let locationsUrl = this.getEndpointUrl('locations', ServerAction.OCPI_PULL_LOCATIONS);
if (partial) {
+ // Take the last day
const momentFrom = moment().utc().subtract(1, 'days').startOf('day');
locationsUrl = `${locationsUrl}?date_from=${momentFrom.format()}&limit=5`;
} else {
+ // Take them all
locationsUrl = `${locationsUrl}?limit=5`;
}
- const company = await this.getAndCheckCompany();
- const sites = await SiteStorage.getSites(this.tenant.id, { companyIDs: [company.id] },
- Constants.DB_PARAMS_MAX_LIMIT);
+ const company = await this.checkAndGetCompany();
+ const sites = await SiteStorage.getSites(this.tenant.id,
+ { companyIDs: [ company.id ] }, Constants.DB_PARAMS_MAX_LIMIT);
let nextResult = true;
do {
- // Log
- Logging.logDebug({
- tenantID: this.tenant.id,
- action: ServerAction.OCPI_PULL_LOCATIONS,
- message: `Retrieve locations from ${locationsUrl}`,
- module: MODULE_NAME, method: 'pullLocations'
- });
// Call IOP
- const response = await this.axiosInstance.get(locationsUrl,
+ const response = await this.axiosInstance.get(
+ locationsUrl,
{
headers: {
Authorization: `Token ${this.ocpiEndpoint.token}`
@@ -210,15 +206,9 @@ export default class EmspOCPIClient extends OCPIClient {
sessionsUrl = `${sessionsUrl}?date_from=${momentFrom.format()}&limit=10`;
let nextResult = true;
do {
- // Log
- Logging.logDebug({
- tenantID: this.tenant.id,
- action: ServerAction.OCPI_PULL_SESSIONS,
- message: `Retrieve OCPI Sessions from ${sessionsUrl}`,
- module: MODULE_NAME, method: 'pullSessions'
- });
// Call IOP
- const response = await this.axiosInstance.get(sessionsUrl,
+ const response = await this.axiosInstance.get(
+ sessionsUrl,
{
headers: {
Authorization: `Token ${this.ocpiEndpoint.token}`
@@ -270,15 +260,9 @@ export default class EmspOCPIClient extends OCPIClient {
cdrsUrl = `${cdrsUrl}?date_from=${momentFrom.format()}&limit=10`;
let nextResult = true;
do {
- // Log
- Logging.logDebug({
- tenantID: this.tenant.id,
- action: ServerAction.OCPI_PULL_CDRS,
- message: `Retrieve CDRs from ${cdrsUrl}`,
- module: MODULE_NAME, method: 'pullCdrs'
- });
// Call IOP
- const response = await this.axiosInstance.get(cdrsUrl,
+ const response = await this.axiosInstance.get(
+ cdrsUrl,
{
headers: {
Authorization: `Token ${this.ocpiEndpoint.token}`
@@ -322,11 +306,13 @@ export default class EmspOCPIClient extends OCPIClient {
module: MODULE_NAME, method: 'processLocation',
detailedMessages: location
});
+ // Handle Site
let site: Site;
const siteName = location.operator && location.operator.name ? location.operator.name
: OCPIUtils.buildOperatorName(this.ocpiEndpoint.countryCode, this.ocpiEndpoint.partyId);
site = sites.find((value) => value.name === siteName);
if (!site) {
+ // Create Site
site = {
name: siteName,
createdOn: new Date(),
@@ -347,15 +333,18 @@ export default class EmspOCPIClient extends OCPIClient {
];
}
site.id = await SiteStorage.saveSite(this.tenant.id, site, false);
+ // Push the Site then it can be retrieve in the next round
sites.push(site);
}
const locationName = site.name + '-' + location.id;
+ // Handle Site Area
const siteAreas = await SiteAreaStorage.getSiteAreas(this.tenant.id, {
siteIDs: [site.id],
search: locationName
}, Constants.DB_PARAMS_SINGLE_RECORD);
let siteArea = siteAreas && siteAreas.result.length === 1 ? siteAreas.result[0] : null;
if (!siteArea) {
+ // Create Site Area
siteArea = {
name: locationName,
createdOn: new Date(),
@@ -378,10 +367,9 @@ export default class EmspOCPIClient extends OCPIClient {
}
siteArea.id = await SiteAreaStorage.saveSiteArea(this.tenant.id, siteArea, false);
}
- if (location.evses && location.evses.length > 0) {
+ if (!Utils.isEmptyArray(location.evses)) {
for (const evse of location.evses) {
- const chargingStationId = OCPIUtils.buildChargingStationId(location.id, evse.uid);
- if (!evse.uid) {
+ if (!evse.evse_id) {
Logging.logDebug({
tenantID: this.tenant.id,
action: ServerAction.OCPI_PULL_LOCATIONS,
@@ -389,77 +377,74 @@ export default class EmspOCPIClient extends OCPIClient {
module: MODULE_NAME, method: 'processLocation',
detailedMessages: location
});
- } else if (evse.status === OCPIEvseStatus.REMOVED) {
- Logging.logDebug({
- tenantID: this.tenant.id,
- action: ServerAction.OCPI_PULL_LOCATIONS,
- message: `Removed Charging Station ID '${chargingStationId}' in Location '${location.name}'`,
- module: MODULE_NAME, method: 'processLocation',
- detailedMessages: location
- });
- await ChargingStationStorage.deleteChargingStation(this.tenant.id, chargingStationId);
- } else {
+ continue;
+ }
+ if (evse.status === OCPIEvseStatus.REMOVED) {
Logging.logDebug({
tenantID: this.tenant.id,
action: ServerAction.OCPI_PULL_LOCATIONS,
- message: `Updated Charging Station ID '${chargingStationId}' in Location '${location.name}'`,
+ message: `Removed Charging Station ID '${evse.evse_id}' in Location '${location.name}'`,
module: MODULE_NAME, method: 'processLocation',
detailedMessages: location
});
+ await ChargingStationStorage.deleteChargingStation(this.tenant.id, evse.evse_id);
+ continue;
+ }
+ // Update Charging Station
const chargingStation = OCPIUtilsService.convertEvseToChargingStation(evse, location);
chargingStation.siteAreaID = siteArea.id;
chargingStation.siteID = siteArea.siteID;
await ChargingStationStorage.saveChargingStation(this.tenant.id, chargingStation);
- }
- }
- }
- }
-
- private async checkToken(tokenUid: string): Promise<boolean> {
- // Get tokens endpoint url
- const tokensUrl = this.getEndpointUrl('tokens', ServerAction.OCPI_CHECK_TOKENS);
- // Read configuration to retrieve
- const countryCode = this.getLocalCountryCode(ServerAction.OCPI_CHECK_TOKENS);
- const partyID = this.getLocalPartyID(ServerAction.OCPI_CHECK_TOKENS);
- // Build url to IOP
- const fullUrl = tokensUrl + `/${countryCode}/${partyID}/${tokenUid}`;
- // Log
Logging.logDebug({
tenantID: this.tenant.id,
- action: ServerAction.OCPI_CHECK_TOKENS,
- message: `Get Token ID '${tokenUid}' from ${fullUrl}`,
- module: MODULE_NAME, method: 'getToken',
- detailedMessages: { tokenUid }
- });
- // Call IOP
- const response = await this.axiosInstance.get(fullUrl,
- {
- headers: {
- Authorization: `Token ${this.ocpiEndpoint.token}`
- },
- });
- Logging.logDebug({
- tenantID: this.tenant.id,
- action: ServerAction.OCPI_CHECK_LOCATIONS,
- message: `Token ID '${tokenUid}' checked successfully`,
- module: MODULE_NAME, method: 'checkToken',
- detailedMessages: { response : response.data }
+ action: ServerAction.OCPI_PULL_LOCATIONS,
+ message: `Updated Charging Station ID '${evse.evse_id}' in Location '${location.name}'`,
+ module: MODULE_NAME, method: 'processLocation',
+ detailedMessages: location
});
- const checkedToken = response.data.data as OCPILocation;
- if (checkedToken) {
- return true;
}
- // Check response
- if (!response.data) {
- throw new BackendError({
- action: ServerAction.OCPI_CHECK_TOKENS,
- message: `Get Token ID '${tokenUid}' failed with status ${JSON.stringify(response)}`,
- module: MODULE_NAME, method: 'getToken',
- detailedMessages: { response: response.data }
- });
}
}
+ // Use by pushToken() for each Token, not scaling if thousand of them
+ // private async checkToken(tokenUid: string): Promise<boolean> {
+ // // Get tokens endpoint url
+ // const tokensUrl = this.getEndpointUrl('tokens', ServerAction.OCPI_CHECK_TOKENS);
+ // // Read configuration to retrieve
+ // const countryCode = this.getLocalCountryCode(ServerAction.OCPI_CHECK_TOKENS);
+ // const partyID = this.getLocalPartyID(ServerAction.OCPI_CHECK_TOKENS);
+ // // Build url to IOP
+ // const fullUrl = tokensUrl + `/${countryCode}/${partyID}/${tokenUid}`;
+ // // Call IOP
+ // const response = await this.axiosInstance.get(
+ // fullUrl,
+ // {
+ // headers: {
+ // Authorization: `Token ${this.ocpiEndpoint.token}`
+ // },
+ // });
+ // Logging.logDebug({
+ // tenantID: this.tenant.id,
+ // action: ServerAction.OCPI_CHECK_LOCATIONS,
+ // message: `Token ID '${tokenUid}' checked successfully`,
+ // module: MODULE_NAME, method: 'checkToken',
+ // detailedMessages: { response : response.data }
+ // });
+ // const checkedToken = response.data.data as OCPILocation;
+ // if (checkedToken) {
+ // return true;
+ // }
+ // // Check response
+ // if (!response.data) {
+ // throw new BackendError({
+ // action: ServerAction.OCPI_CHECK_TOKENS,
+ // message: `Get Token ID '${tokenUid}' failed with status ${JSON.stringify(response)}`,
+ // module: MODULE_NAME, method: 'getToken',
+ // detailedMessages: { response: response.data }
+ // });
+ // }
+ // }
+
public async pushToken(token: OCPIToken): Promise<boolean> {
// Get tokens endpoint url
const tokensUrl = this.getEndpointUrl('tokens', ServerAction.OCPI_PUSH_TOKENS);
@@ -468,23 +453,17 @@ export default class EmspOCPIClient extends OCPIClient {
const partyID = this.getLocalPartyID(ServerAction.OCPI_PUSH_TOKENS);
// Build url to IOP
const fullUrl = tokensUrl + `/${countryCode}/${partyID}/${token.uid}`;
- // Log
- Logging.logDebug({
- tenantID: this.tenant.id,
- action: ServerAction.OCPI_PUSH_TOKENS,
- message: `Push Token ID '${token.uid}' to ${fullUrl}`,
- module: MODULE_NAME, method: 'pushToken',
- detailedMessages: { token }
- });
// Call IOP
- await this.axiosInstance.put(fullUrl, token,
+ await this.axiosInstance.put(
+ fullUrl,
+ token,
{
headers: {
Authorization: `Token ${this.ocpiEndpoint.token}`,
'Content-Type': 'application/json'
},
});
- return this.checkToken(token.uid);
+ return true;
}
public async remoteStartSession(chargingStation: ChargingStation, connectorId: number, tagId: string): Promise<OCPICommandResponse> {
@@ -528,17 +507,10 @@ export default class EmspOCPIClient extends OCPIClient {
location_id: chargingStation.iccid,
authorization_id: authorizationId
};
- // Log
- Logging.logDebug({
- tenantID: this.tenant.id,
- action: ServerAction.OCPI_START_SESSION,
- source: chargingStation.id,
- message: `Connector ID '${connectorId}' > OCPI Remote Start Session with Tad ID '${tagId}' at ${commandUrl}`,
- module: MODULE_NAME, method: 'remoteStartSession',
- detailedMessages: { payload }
- });
// Call IOP
- const response = await this.axiosInstance.post(commandUrl, payload,
+ const response = await this.axiosInstance.post(
+ commandUrl,
+ payload,
{
headers: {
'Authorization': `Token ${this.ocpiEndpoint.token}`,
@@ -560,6 +532,7 @@ export default class EmspOCPIClient extends OCPIClient {
// Get command endpoint url
const commandUrl = this.getEndpointUrl('commands', ServerAction.OCPI_START_SESSION) + '/' + OCPICommandType.STOP_SESSION;
const callbackUrl = this.getLocalEndpointUrl('commands') + '/' + OCPICommandType.STOP_SESSION;
+ // Get transaction
const transaction = await TransactionStorage.getTransaction(this.tenant.id, transactionId);
if (!transaction || !transaction.ocpiData || !transaction.ocpiData.session || transaction.issuer) {
throw new BackendError({
@@ -574,17 +547,10 @@ export default class EmspOCPIClient extends OCPIClient {
response_url: callbackUrl + '/' + transaction.ocpiData.session.id,
session_id: transaction.ocpiData.session.id
};
- // Log
- Logging.logDebug({
- tenantID: this.tenant.id,
- action: ServerAction.OCPI_STOP_SESSION,
- source: transaction.chargeBoxID,
- message: `Connector ID '${transaction.connectorId}' > OCPI Remote Stop Session ID '${transactionId}' at ${commandUrl}`,
- module: MODULE_NAME, method: 'remoteStopSession',
- detailedMessages: { payload }
- });
// Call IOP
- const response = await this.axiosInstance.post(commandUrl, payload,
+ const response = await this.axiosInstance.post(
+ commandUrl,
+ payload,
{
headers: {
'Authorization': `Token ${this.ocpiEndpoint.token}`,

MODIFY
src/integration/pricing/simple-pricing/SimplePricingIntegration.ts
src/integration/pricing/simple-pricing/SimplePricingIntegration.ts
-import { PricingSettingsType, SimplePricingSetting } from '../../../types/Setting';
+import { PricedConsumption, PricingSource } from '../../../types/Pricing';
import Consumption from '../../../types/Consumption';
-import { PricedConsumption } from '../../../types/Pricing';
import PricingIntegration from '../PricingIntegration';
+import { SimplePricingSetting } from '../../../types/Setting';
import Transaction from '../../../types/Transaction';
import Utils from '../../../utils/Utils';
@@ -35,7 +35,7 @@ export default class SimplePricingIntegration extends PricingIntegration<SimpleP
roundedAmount = 0;
}
const pricedConsumption: PricedConsumption = {
- pricingSource: PricingSettingsType.SIMPLE,
+ pricingSource: PricingSource.SIMPLE,
amount: amount,
roundedAmount: roundedAmount,
currencyCode: this.settings.currency,

MODIFY
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/OCPIUtilsService.ts
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/OCPIUtilsService.ts
@@ -28,6 +28,7 @@ import OCPIEndpoint from '../../../../types/ocpi/OCPIEndpoint';
import { OCPIRole } from '../../../../types/ocpi/OCPIRole';
import { OCPIStatusCode } from '../../../../types/ocpi/OCPIStatusCode';
import OCPIUtils from '../../OCPIUtils';
+import { PricingSource } from '../../../../types/Pricing';
import RoamingUtils from '../../../../utils/RoamingUtils';
import { ServerAction } from '../../../../types/Server';
import SettingStorage from '../../../../storage/mongodb/SettingStorage';
@@ -746,24 +747,14 @@ export default class OCPIUtilsService {
});
}
const evse = session.location.evses[0];
- const chargingStationId = OCPIUtils.buildChargingStationId(session.location.id, evse.uid);
- const chargingStation = await ChargingStationStorage.getChargingStationBySerialNumber(tenantId, chargingStationId);
+ const chargingStation = await ChargingStationStorage.getChargingStationByOcpiLocationUid(
+ tenantId, session.location.id, evse.uid);
if (!chargingStation) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
module: MODULE_NAME, method: 'updateTransaction',
errorCode: HTTPError.GENERAL_ERROR,
- message: `No Charging Station found for ID '${evse.uid}'`,
- detailedMessages: { session },
- ocpiError: OCPIStatusCode.CODE_2003_UNKNOWN_LOCATION_ERROR
- });
- }
- if (chargingStation.issuer) {
- throw new AppError({
- source: Constants.CENTRAL_SERVER,
- module: MODULE_NAME, method: 'updateTransaction',
- errorCode: HTTPError.GENERAL_ERROR,
- message: `OCPI Transaction is not authorized on charging station ${evse.uid} issued locally`,
+ message: `No Charging Station found with ID '${evse.uid}' in Location '${session.location.id}'`,
detailedMessages: { session },
ocpiError: OCPIStatusCode.CODE_2003_UNKNOWN_LOCATION_ERROR
});
@@ -789,7 +780,7 @@ export default class OCPIUtilsService {
stateOfCharge: 0,
currentStateOfCharge: 0,
currentTotalInactivitySecs: 0,
- pricingSource: 'ocpi',
+ pricingSource: PricingSource.OCPI,
currentInactivityStatus: InactivityStatus.INFO,
currentInstantWatts: 0,
currentConsumptionWh: 0,
@@ -818,7 +809,7 @@ export default class OCPIUtilsService {
return;
}
if (session.kwh > 0) {
- await OCPIUtilsService.computeConsumption(tenantId, transaction, session);
+ await OCPIUtilsService.computeAndSaveConsumption(tenantId, transaction, session);
}
if (!transaction.ocpiData) {
transaction.ocpiData = {};
@@ -951,7 +942,7 @@ export default class OCPIUtilsService {
}
}
- private static async computeConsumption(tenantId: string, transaction: Transaction, session: OCPISession): Promise<void> {
+ private static async computeAndSaveConsumption(tenantId: string, transaction: Transaction, session: OCPISession): Promise<void> {
const consumptionWh = Utils.createDecimal(session.kwh).mul(1000).minus(Utils.convertToFloat(transaction.lastConsumption.value)).toNumber();
const duration = Utils.createDecimal(moment(session.last_updated).diff(transaction.lastConsumption.timestamp, 'milliseconds')).div(1000).toNumber();
if (consumptionWh > 0 || duration > 0) {

MODIFY
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/emsp/EMSPLocationsEndpoint.ts
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/emsp/EMSPLocationsEndpoint.ts
@@ -59,8 +59,8 @@ export default class EMSPLocationsEndpoint extends AbstractEndpoint {
});
}
if (evseUid) {
- const chargingStationId = OCPIUtils.buildChargingStationId(locationId, evseUid);
- const chargingStation = await ChargingStationStorage.getChargingStationBySerialNumber(tenant.id, chargingStationId);
+ const chargingStation = await ChargingStationStorage.getChargingStationByOcpiLocationUid(
+ tenant.id, locationId, evseUid);
if (!chargingStation) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
@@ -109,7 +109,7 @@ export default class EMSPLocationsEndpoint extends AbstractEndpoint {
}
const siteName = OCPIUtils.buildOperatorName(countryCode, partyId);
const ocpiClient = await OCPIClientFactory.getEmspOcpiClient(tenant, ocpiEndpoint);
- const company = await ocpiClient.getAndCheckCompany();
+ const company = await ocpiClient.checkAndGetCompany();
const sites = await SiteStorage.getSites(tenant.id, { companyIDs: [company.id], search: siteName }, Constants.DB_PARAMS_SINGLE_RECORD);
if (evseUid && connectorId) {
await this.updateConnector(tenant, locationId, evseUid, connectorId, req.body);
@@ -186,34 +186,48 @@ export default class EMSPLocationsEndpoint extends AbstractEndpoint {
}
private async updateEvse(tenant: Tenant, locationId: string, evseUid: string, evse: OCPIEvse, location?: OCPILocation) {
- const chargingStationId = OCPIUtils.buildChargingStationId(locationId, evseUid);
if (evse.status === OCPIEvseStatus.REMOVED) {
- Logging.logDebug({
+ const chargingStation = await ChargingStationStorage.getChargingStationByOcpiLocationUid(
+ tenant.id, location.id, evseUid);
+ if (chargingStation) {
+ // Delete
+ await ChargingStationStorage.deleteChargingStation(tenant.id, chargingStation.id);
+ Logging.logInfo({
tenantID: tenant.id,
action: ServerAction.OCPI_PATCH_LOCATIONS,
- message: `Delete removed Charging Station '${evseUid}' of Location ID '${locationId}'`,
+ message: `Charging Station '${evseUid}' of Location ID '${locationId}' has been deleted`,
source: Constants.CENTRAL_SERVER,
- module: MODULE_NAME, method: 'updateLocation',
+ module: MODULE_NAME, method: 'updateEvse',
detailedMessages: location
});
- await ChargingStationStorage.deleteChargingStationBySerialNumber(tenant.id, chargingStationId);
} else {
- Logging.logDebug({
+ Logging.logError({
tenantID: tenant.id,
action: ServerAction.OCPI_PATCH_LOCATIONS,
- message: `Update Charging Station '${evseUid}' of Location ID '${locationId}'`,
+ message: `Charging Station '${evseUid}' of Location ID '${locationId}' does not exist and cannot be deleted`,
source: Constants.CENTRAL_SERVER,
- module: MODULE_NAME, method: 'updateLocation',
+ module: MODULE_NAME, method: 'updateEvse',
detailedMessages: location
});
+ }
+ } else {
+ // Create/Update
const chargingStation = OCPIUtilsService.convertEvseToChargingStation(evse, location);
await ChargingStationStorage.saveChargingStation(tenant.id, chargingStation);
+ Logging.logDebug({
+ tenantID: tenant.id,
+ action: ServerAction.OCPI_PATCH_LOCATIONS,
+ message: `Charging Station '${evseUid}' of Location ID '${locationId}' has been updated`,
+ source: Constants.CENTRAL_SERVER,
+ module: MODULE_NAME, method: 'updateEvse',
+ detailedMessages: location
+ });
}
}
private async updateConnector(tenant: Tenant, locationId: string, evseUid: string, connectorId: string, ocpiConnector: OCPIConnector) {
- const chargingStationId = OCPIUtils.buildChargingStationId(locationId, evseUid);
- const chargingStation = await ChargingStationStorage.getChargingStationBySerialNumber(tenant.id, chargingStationId);
+ const chargingStation = await ChargingStationStorage.getChargingStationByOcpiLocationUid(
+ tenant.id, locationId, evseUid);
if (!chargingStation) {
Logging.logError({
tenantID: tenant.id,

MODIFY
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/emsp/EMSPTokensEndpoint.ts
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/emsp/EMSPTokensEndpoint.ts
@@ -98,9 +98,9 @@ export default class EMSPTokensEndpoint extends AbstractEndpoint {
ocpiError: OCPIStatusCode.CODE_2001_INVALID_PARAMETER_ERROR
});
}
- const chargingStationId = OCPIUtils.buildChargingStationId(locationReference.location_id, locationReference.evse_uids[0]);
- const chargingStation = await ChargingStationStorage.getChargingStationBySerialNumber(tenant.id, chargingStationId);
- if (!chargingStation || chargingStation.issuer) {
+ const chargingStation = await ChargingStationStorage.getChargingStationByOcpiLocationUid(
+ tenant.id, locationReference.location_id, locationReference.evse_uids[0]);
+ if (!chargingStation) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
module: MODULE_NAME, method: 'authorizeRequest',

MODIFY
src/storage/mongodb/ChargingStationStorage.ts
src/storage/mongodb/ChargingStationStorage.ts
@@ -154,10 +154,20 @@ export default class ChargingStationStorage {
return chargingStationsMDB.count === 1 ? chargingStationsMDB.result[0] : null;
}
+ public static async getChargingStationByOcpiLocationUid(tenantID: string, ocpiLocation: string = Constants.UNKNOWN_STRING_ID,
+ ocpiUid: string = Constants.UNKNOWN_STRING_ID, projectFields?: string[]): Promise<ChargingStation> {
+ const chargingStationsMDB = await ChargingStationStorage.getChargingStations(tenantID, {
+ siteIDs: [ocpiLocation],
+ ocpiUid: ocpiUid,
+ issuer: false,
+ }, Constants.DB_PARAMS_SINGLE_RECORD, projectFields);
+ return chargingStationsMDB.count === 1 ? chargingStationsMDB.result[0] : null;
+ }
+
public static async getChargingStations(tenantID: string,
params: {
search?: string; chargingStationIDs?: string[]; chargingStationSerialNumbers?: string[]; siteAreaIDs?: string[]; withNoSiteArea?: boolean;
- connectorStatuses?: string[]; connectorTypes?: string[]; statusChangedBefore?: Date;
+ connectorStatuses?: string[]; connectorTypes?: string[]; statusChangedBefore?: Date; ocpiUid?: string;
siteIDs?: string[]; withSite?: boolean; includeDeleted?: boolean; offlineSince?: Date; issuer?: boolean;
locCoordinates?: number[]; locMaxDistanceMeters?: number; public?: boolean;
},
@@ -218,6 +228,10 @@ export default class ChargingStationStorage {
$in: params.chargingStationSerialNumbers
};
}
+ // OCPI Uids
+ if (params.ocpiUid) {
+ filters['ocpiData.evses.uid'] = params.ocpiUid;
+ }
// Filter on lastSeen
if (params.offlineSince && moment(params.offlineSince).isValid()) {
filters.lastSeen = { $lte: params.offlineSince };
@@ -661,13 +675,6 @@ export default class ChargingStationStorage {
await Logging.traceEnd(tenantID, MODULE_NAME, 'deleteChargingStation', uniqueTimerID, { id });
}
- public static async deleteChargingStationBySerialNumber(tenantID: string, chargingStationSerialNumber?: string): Promise<void> {
- const chargingStation = await ChargingStationStorage.getChargingStationBySerialNumber(tenantID, chargingStationSerialNumber);
- if (chargingStation) {
- await ChargingStationStorage.deleteChargingStation(tenantID, chargingStation.id);
- }
- }
-
public static async getOcppParameterValue(tenantID: string, chargeBoxID: string, paramName: string): Promise<string> {
const configuration = await ChargingStationStorage.getOcppParameters(tenantID, chargeBoxID);
let value: string = null;

MODIFY
src/types/Pricing.ts
src/types/Pricing.ts
@@ -25,5 +25,12 @@ export interface PricedConsumption {
cumulatedAmount: number;
roundedAmount: number;
currencyCode: string;
- pricingSource: string;
+ pricingSource: PricingSource;
}
+
+export enum PricingSource {
+ SIMPLE = 'simple',
+ CONVERGENT_CHARGING = 'convergentCharging',
+ OCPI = 'ocpi',
+}
+

Removed non performant coding. Added PricingSource enum, add getChargingStationByOcpiLocationUid in storage (removed serialNumber). Removed deleteChargingStationBySerialNumber().