Check Emsp endpoint
MODIFY
src/client/ocpi/CpoOCPIClient.ts
src/client/ocpi/CpoOCPIClient.ts
@@ -2,7 +2,7 @@ import ChargingStation, { Connector } from '../../types/ChargingStation';
import { OCPIAllowed, OCPIAuthorizationInfo } from '../../types/ocpi/OCPIAuthorizationInfo';
import { OCPIAuthMethod, OCPISession, OCPISessionStatus } from '../../types/ocpi/OCPISession';
import { OCPIEvse, OCPIEvseStatus } from '../../types/ocpi/OCPIEvse';
-import { OCPILocation, OCPILocationReference } from '../../types/ocpi/OCPILocation';
+import { OCPILocation, OCPILocationOptions, OCPILocationReference } from '../../types/ocpi/OCPILocation';
import { AxiosResponse } from 'axios';
import BackendError from '../../exception/BackendError';
@@ -547,7 +547,7 @@ export default class CpoOCPIClient extends OCPIClient {
// Perfs trace
const startTime = new Date().getTime();
// Define get option
- const options = {
+ const options: OCPILocationOptions = {
addChargeBoxID: true,
countryID: this.getLocalCountryCode(ServerAction.OCPI_CHECK_LOCATIONS),
partyID: this.getLocalPartyID(ServerAction.OCPI_CHECK_LOCATIONS)
@@ -640,7 +640,7 @@ export default class CpoOCPIClient extends OCPIClient {
// Perfs trace
const startTime = new Date().getTime();
// Define get option
- const options = {
+ const options: OCPILocationOptions = {
addChargeBoxID: true,
countryID: this.getLocalCountryCode(ServerAction.OCPI_PATCH_STATUS),
partyID: this.getLocalPartyID(ServerAction.OCPI_PATCH_STATUS)

MODIFY
src/client/ocpi/EmspOCPIClient.ts
src/client/ocpi/EmspOCPIClient.ts
+import { OCPILocation, OCPILocationOptions } from '../../types/ocpi/OCPILocation';
import { OCPIToken, OCPITokenType, OCPITokenWhitelist } from '../../types/ocpi/OCPIToken';
import BackendError from '../../exception/BackendError';
@@ -15,7 +16,6 @@ import { OCPICommandType } from '../../types/ocpi/OCPICommandType';
import OCPIEndpoint from '../../types/ocpi/OCPIEndpoint';
import OCPIEndpointStorage from '../../storage/mongodb/OCPIEndpointStorage';
import { OCPIEvseStatus } from '../../types/ocpi/OCPIEvse';
-import { OCPILocation } from '../../types/ocpi/OCPILocation';
import { OCPIResult } from '../../types/ocpi/OCPIResult';
import { OCPIRole } from '../../types/ocpi/OCPIRole';
import { OCPISession } from '../../types/ocpi/OCPISession';
@@ -24,6 +24,7 @@ import { OCPIStopSession } from '../../types/ocpi/OCPIStopSession';
import OCPIUtils from '../../server/ocpi/OCPIUtils';
import OCPIUtilsService from '../../server/ocpi/ocpi-services-impl/ocpi-2.1.1/OCPIUtilsService';
import { OcpiSetting } from '../../types/Setting';
+import RoamingUtils from '../../utils/RoamingUtils';
import { ServerAction } from '../../types/Server';
import Site from '../../types/Site';
import SiteArea from '../../types/SiteArea';
@@ -301,8 +302,7 @@ export default class EmspOCPIClient extends OCPIClient {
public async processLocation(location: OCPILocation, company: Company, sites: Site[]): Promise<void> {
// Handle Site
let site: Site;
- const siteName = location.operator && location.operator.name ? location.operator.name
- : OCPIUtils.buildOperatorName(this.ocpiEndpoint.countryCode, this.ocpiEndpoint.partyId);
+ const siteName = location.operator?.name ?? OCPIUtils.buildOperatorName(this.ocpiEndpoint.countryCode, this.ocpiEndpoint.partyId);
site = sites.find((value) => value.name === siteName);
if (!site) {
// Create Site
@@ -362,25 +362,29 @@ export default class EmspOCPIClient extends OCPIClient {
}
if (!Utils.isEmptyArray(location.evses)) {
for (const evse of location.evses) {
- if (!evse.evse_id) {
- Logging.logDebug({
- tenantID: this.tenant.id,
+ if (!evse.uid) {
+ throw new BackendError({
action: ServerAction.OCPI_PULL_LOCATIONS,
- message: `Missing Charging Station ID in Location '${location.name}'`,
+ message: `Missing Charging Station EVSE UID in Location ID '${location.id}'`,
module: MODULE_NAME, method: 'processLocation',
- detailedMessages: location
+ detailedMessages: { evse, location }
});
- continue;
}
if (evse.status === OCPIEvseStatus.REMOVED) {
+ // Get existing charging station
+ const currentChargingStation = await ChargingStationStorage.getChargingStationByOcpiLocationUid(
+ this.tenant.id, location.id, evse.uid, ['id']
+ );
+ if (currentChargingStation) {
+ await ChargingStationStorage.deleteChargingStation(this.tenant.id, currentChargingStation.id);
Logging.logDebug({
tenantID: this.tenant.id,
action: ServerAction.OCPI_PULL_LOCATIONS,
- message: `Removed Charging Station ID '${evse.evse_id}' in Location '${location.name}'`,
+ message: `Removed Charging Station EVSE UID '${evse.uid}' in Location ID '${location.id}'`,
module: MODULE_NAME, method: 'processLocation',
- detailedMessages: location
+ detailedMessages: { evse, location }
});
- await ChargingStationStorage.deleteChargingStation(this.tenant.id, evse.evse_id);
+ }
continue;
}
// Update Charging Station

MODIFY
src/client/oicp/CpoOICPClient.ts
src/client/oicp/CpoOICPClient.ts
@@ -13,6 +13,7 @@ import Constants from '../../utils/Constants';
import { HTTPError } from '../../types/HTTPError';
import Logging from '../../utils/Logging';
import NotificationHandler from '../../notification/NotificationHandler';
+import { OCPILocationOptions } from '../../types/ocpi/OCPILocation';
import OCPPStorage from '../../storage/mongodb/OCPPStorage';
import { OICPAcknowledgment } from '../../types/oicp/OICPAcknowledgment';
import { OICPAuthorizationStatus } from '../../types/oicp/OICPAuthentication';
@@ -57,7 +58,7 @@ export default class CpoOICPClient extends OICPClient {
} else {
siteArea = chargingStation.siteArea;
}
- const options = {
+ const options: OCPILocationOptions = {
countryID: this.getLocalCountryCode(ServerAction.OICP_PUSH_SESSIONS),
partyID: this.getLocalPartyID(ServerAction.OICP_PUSH_SESSIONS),
addChargeBoxID: true
@@ -228,7 +229,7 @@ export default class CpoOICPClient extends OICPClient {
// Perfs trace
const startTime = new Date().getTime();
// Define get option
- const options = {
+ const options: OCPILocationOptions= {
addChargeBoxID: true,
countryID: this.getLocalCountryCode(ServerAction.OICP_PUSH_EVSE_DATA),
partyID: this.getLocalPartyID(ServerAction.OICP_PUSH_EVSE_DATA)
@@ -363,7 +364,7 @@ export default class CpoOICPClient extends OICPClient {
// Perfs trace
const startTime = new Date().getTime();
// Define get option
- const options = {
+ const options: OCPILocationOptions = {
addChargeBoxID: true,
countryID: this.getLocalCountryCode(ServerAction.OICP_PUSH_EVSE_STATUSES),
partyID: this.getLocalPartyID(ServerAction.OICP_PUSH_EVSE_STATUSES)
@@ -493,7 +494,7 @@ export default class CpoOICPClient extends OICPClient {
});
}
// Define get option
- const options = {
+ const options: OCPILocationOptions = {
addChargeBoxID: true,
countryID: this.getLocalCountryCode(ServerAction.OICP_PUSH_EVSE_STATUSES),
partyID: this.getLocalPartyID(ServerAction.OICP_PUSH_EVSE_STATUSES)

MODIFY
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/CPOService.ts
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/CPOService.ts
@@ -18,7 +18,6 @@ export default class CPOService extends AbstractOCPIService {
// Create OCPI Service
constructor(ocpiRestConfig: OCPIServiceConfiguration) {
super(ocpiRestConfig, CPOService.PATH, CPOService.VERSION);
-
// Register Endpoints
this.registerEndpoint(new CredentialsEndpoint(this));
this.registerEndpoint(new CPOLocationsEndpoint(this));

MODIFY
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/EMSPService.ts
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/EMSPService.ts
@@ -17,7 +17,6 @@ export default class EMSPService extends AbstractOCPIService {
// Create OCPI Service
constructor(ocpiRestConfig: OCPIServiceConfiguration) {
super(ocpiRestConfig, EMSPService.PATH, EMSPService.VERSION);
-
// Register Endpoints
this.registerEndpoint(new CredentialsEndpoint(this));
this.registerEndpoint(new EMSPLocationsEndpoint(this));

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
@@ -11,6 +11,7 @@ import Transaction, { InactivityStatus } from '../../../../types/Transaction';
import User, { UserRole, UserStatus } from '../../../../types/User';
import AppError from '../../../../exception/AppError';
+import BackendError from '../../../../exception/BackendError';
import { ChargePointStatus } from '../../../../types/ocpp/OCPPServer';
import ChargingStationStorage from '../../../../storage/mongodb/ChargingStationStorage';
import Configuration from '../../../../utils/Configuration';
@@ -73,7 +74,6 @@ export default class OCPIUtilsService {
public static convertEvseToChargingStation(evse: Partial<OCPIEvse>, location?: OCPILocation): ChargingStation {
const chargingStation = {
- id: evse.evse_id,
maximumPower: 0,
issuer: false,
connectors: [],
@@ -110,6 +110,15 @@ export default class OCPIUtilsService {
connectorId++;
}
}
+ // Build ID
+ chargingStation.id = evse.evse_id;
+ if (!chargingStation.id) {
+ throw new BackendError({
+ message: `Cannot find Charging Station EVSE ID`,
+ module: MODULE_NAME, method: 'convertEvseToChargingStation',
+ detailedMessages: { evse, location }
+ });
+ }
return chargingStation;
}
@@ -326,7 +335,8 @@ export default class OCPIUtilsService {
return tariff;
}
- public static convertChargingStationToOCPILocation(tenant: Tenant, site: Site, chargingStation: ChargingStation, connectorId: number, countryId: string, partyId: string): OCPILocation {
+ public static convertChargingStationToOCPILocation(tenant: Tenant, site: Site, chargingStation: ChargingStation,
+ connectorId: number, countryId: string, partyId: string): OCPILocation {
const connectors: OCPIConnector[] = [];
let status: ChargePointStatus;
for (const chargingStationConnector of chargingStation.connectors) {
@@ -350,7 +360,8 @@ export default class OCPIUtilsService {
type: OCPILocationType.UNKNOWN,
evses: [{
uid: OCPIUtils.buildEvseUID(chargingStation, Utils.getConnectorFromID(chargingStation, connectorId)),
- evse_id: RoamingUtils.buildEvseID(countryId, partyId, chargingStation, Utils.getConnectorFromID(chargingStation, connectorId)),
+ evse_id: RoamingUtils.buildEvseID(countryId, partyId, chargingStation.id,
+ Utils.getConnectorFromID(chargingStation, connectorId).connectorId),
status: OCPIUtilsService.convertStatus2OCPIStatus(status),
capabilities: [OCPICapability.REMOTE_START_STOP_CAPABLE, OCPICapability.RFID_READER],
connectors: connectors,
@@ -490,7 +501,8 @@ export default class OCPIUtilsService {
const evses = connectors.map((connector) => {
const evse: OCPIEvse = {
uid: OCPIUtils.buildEvseUID(chargingStation, connector),
- evse_id: RoamingUtils.buildEvseID(options.countryID, options.partyID, chargingStation, connector),
+ evse_id: RoamingUtils.buildEvseID(options.countryID, options.partyID,
+ chargingStation.id, connector.connectorId),
status: OCPIUtilsService.convertStatus2OCPIStatus(connector.status),
capabilities: [OCPICapability.REMOTE_START_STOP_CAPABLE, OCPICapability.RFID_READER],
connectors: [OCPIUtilsService.convertConnector2OCPIConnector(tenant, chargingStation, connector, options.countryID, options.partyID)],
@@ -527,7 +539,7 @@ export default class OCPIUtilsService {
const evse: OCPIEvse = {
// Force the connector id to always be 1 on charging station that have mutually exclusive connectors
uid: OCPIUtils.buildEvseUID(chargingStation, { connectorId: 1, status: connectorOneStatus }),
- evse_id: RoamingUtils.buildEvseID(options.countryID, options.partyID, chargingStation, { connectorId: 1, status: connectorOneStatus }),
+ evse_id: RoamingUtils.buildEvseID(options.countryID, options.partyID, chargingStation.id, 1),
status: OCPIUtilsService.convertStatus2OCPIStatus(connectorOneStatus),
capabilities: [OCPICapability.REMOTE_START_STOP_CAPABLE, OCPICapability.RFID_READER],
connectors: ocpiConnectors,
@@ -613,7 +625,7 @@ export default class OCPIUtilsService {
const amperage = OCPIUtilsService.getChargingStationOCPIAmperage(chargingStation, chargePoint, connector.connectorId);
const ocpiNumberOfConnectedPhases = OCPIUtilsService.getChargingStationOCPINumberOfConnectedPhases(chargingStation, chargePoint, connector.connectorId);
return {
- id: RoamingUtils.buildEvseID(countryId, partyId, chargingStation, connector),
+ id: RoamingUtils.buildEvseID(countryId, partyId, chargingStation.id, connector.connectorId),
standard: type,
format: format,
voltage: voltage,
@@ -756,8 +768,8 @@ export default class OCPIUtilsService {
});
}
const evse = session.location.evses[0];
- const chargingStation = await ChargingStationStorage.getChargingStationByOcpiLocationUid(
- tenantId, session.location.id, evse.uid);
+ const chargingStation = await ChargingStationStorage.getChargingStationByOcpiEvseID(
+ tenantId, evse.evse_id);
if (!chargingStation) {
throw new AppError({
source: Constants.CENTRAL_SERVER,

MODIFY
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/cpo/CPOLocationsEndpoint.ts
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/cpo/CPOLocationsEndpoint.ts
@@ -7,6 +7,7 @@ import Constants from '../../../../../utils/Constants';
import { HTTPError } from '../../../../../types/HTTPError';
import OCPIClientFactory from '../../../../../client/ocpi/OCPIClientFactory';
import OCPIEndpoint from '../../../../../types/ocpi/OCPIEndpoint';
+import { OCPILocationOptions } from '../../../../../types/ocpi/OCPILocation';
import { OCPIResponse } from '../../../../../types/ocpi/OCPIResponse';
import { OCPIStatusCode } from '../../../../../types/ocpi/OCPIStatusCode';
import OCPIUtils from '../../../OCPIUtils';
@@ -44,7 +45,7 @@ export default class CPOLocationsEndpoint extends AbstractEndpoint {
let payload = {};
const ocpiClient = await OCPIClientFactory.getOcpiClient(tenant, ocpiEndpoint);
// Define get option
- const options = {
+ const options: OCPILocationOptions = {
addChargeBoxID: true,
countryID: ocpiClient.getLocalCountryCode(ServerAction.OCPI_GET_LOCATIONS),
partyID: ocpiClient.getLocalPartyID(ServerAction.OCPI_GET_LOCATIONS)

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
import { NextFunction, Request, Response } from 'express';
import { OCPIEvse, OCPIEvseStatus } from '../../../../../types/ocpi/OCPIEvse';
+import { OCPILocation, OCPILocationOptions } from '../../../../../types/ocpi/OCPILocation';
import AbstractEndpoint from '../../AbstractEndpoint';
import AbstractOCPIService from '../../../AbstractOCPIService';
@@ -13,7 +14,6 @@ import Logging from '../../../../../utils/Logging';
import OCPIClientFactory from '../../../../../client/ocpi/OCPIClientFactory';
import { OCPIConnector } from '../../../../../types/ocpi/OCPIConnector';
import OCPIEndpoint from '../../../../../types/ocpi/OCPIEndpoint';
-import { OCPILocation } from '../../../../../types/ocpi/OCPILocation';
import { OCPIResponse } from '../../../../../types/ocpi/OCPIResponse';
import { OCPIStatusCode } from '../../../../../types/ocpi/OCPIStatusCode';
import OCPIUtils from '../../../OCPIUtils';
@@ -58,6 +58,10 @@ export default class EMSPLocationsEndpoint extends AbstractEndpoint {
ocpiError: OCPIStatusCode.CODE_2001_INVALID_PARAMETER_ERROR
});
}
+ const options: OCPILocationOptions = {
+ countryID: countryCode,
+ partyID: partyId
+ };
if (evseUid) {
const chargingStation = await ChargingStationStorage.getChargingStationByOcpiLocationUid(
tenant.id, locationId, evseUid);
@@ -73,7 +77,7 @@ export default class EMSPLocationsEndpoint extends AbstractEndpoint {
if (connectorId) {
await this.patchConnector(tenant, chargingStation, connectorId, req.body);
} else {
- await this.patchEvse(tenant, chargingStation, req.body);
+ await this.patchEvse(tenant, chargingStation, req.body, options);
}
} else {
Logging.logDebug({
@@ -90,9 +94,7 @@ export default class EMSPLocationsEndpoint extends AbstractEndpoint {
private async putLocationRequest(req: Request, res: Response, next: NextFunction, tenant: Tenant, ocpiEndpoint: OCPIEndpoint): Promise<OCPIResponse> {
const urlSegment = req.path.substring(1).split('/');
- // Remove action
urlSegment.shift();
- // Get filters
const countryCode = urlSegment.shift();
const partyId = urlSegment.shift();
const locationId = urlSegment.shift();
@@ -121,7 +123,7 @@ export default class EMSPLocationsEndpoint extends AbstractEndpoint {
return OCPIUtils.success();
}
- private async patchEvse(tenant: Tenant, chargingStation: ChargingStation, evse: Partial<OCPIEvse>) {
+ private async patchEvse(tenant: Tenant, chargingStation: ChargingStation, evse: Partial<OCPIEvse>, options: OCPILocationOptions) {
const chargingStationEvse = chargingStation.ocpiData.evses.find((evse) => evse.uid = evse.uid);
if (evse.status) {
if (evse.status === OCPIEvseStatus.REMOVED) {

MODIFY
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/emsp/EMSPSessionsEndpoint.ts
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/emsp/EMSPSessionsEndpoint.ts
@@ -51,7 +51,6 @@ export default class EMSPSessionsEndpoint extends AbstractEndpoint {
ocpiError: OCPIStatusCode.CODE_2001_INVALID_PARAMETER_ERROR
});
}
-
const transaction: Transaction = await TransactionStorage.getOCPITransaction(tenant.id, sessionId);
if (!transaction) {
throw new AppError({
@@ -102,12 +101,10 @@ export default class EMSPSessionsEndpoint extends AbstractEndpoint {
const urlSegment = req.path.substring(1).split('/');
// Remove action
urlSegment.shift();
-
// Get filters
const countryCode = urlSegment.shift();
const partyId = urlSegment.shift();
const sessionId = urlSegment.shift();
-
if (!countryCode || !partyId || !sessionId) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
@@ -117,7 +114,7 @@ export default class EMSPSessionsEndpoint extends AbstractEndpoint {
ocpiError: OCPIStatusCode.CODE_2001_INVALID_PARAMETER_ERROR
});
}
- const transaction: Transaction = await TransactionStorage.getOCPITransaction(tenant.id, sessionId);
+ const transaction = await TransactionStorage.getOCPITransaction(tenant.id, sessionId);
if (!transaction) {
throw new AppError({
source: Constants.CENTRAL_SERVER,

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,8 +98,8 @@ export default class EMSPTokensEndpoint extends AbstractEndpoint {
ocpiError: OCPIStatusCode.CODE_2001_INVALID_PARAMETER_ERROR
});
}
- const chargingStation = await ChargingStationStorage.getChargingStationByOcpiLocationUid(
- tenant.id, locationReference.location_id, locationReference.evse_uids[0]);
+ const chargingStation = await ChargingStationStorage.getChargingStationByOcpiEvseID(
+ tenant.id, locationReference.evse_uids[0]);
if (!chargingStation) {
throw new AppError({
source: Constants.CENTRAL_SERVER,

MODIFY
src/server/oicp/OICPUtils.ts
src/server/oicp/OICPUtils.ts
@@ -86,7 +86,7 @@ export default class OICPUtils {
if (chargingStations && chargingStations.result) {
for (const cs of chargingStations.result) {
cs.connectors.forEach((conn) => {
- if (evseID === RoamingUtils.buildEvseID(evseIDComponents.countryCode, evseIDComponents.partyId, cs, conn)) {
+ if (evseID === RoamingUtils.buildEvseID(evseIDComponents.countryCode, evseIDComponents.partyId, cs.id, conn.connectorId)) {
chargingStation = cs;
connector = conn;
}

MODIFY
src/server/oicp/oicp-services-impl/oicp-2.3.0/OICPMapping.ts
src/server/oicp/oicp-services-impl/oicp-2.3.0/OICPMapping.ts
@@ -60,7 +60,7 @@ export default class OICPMapping {
*/
public static convertConnector2EvseStatus(tenant: Tenant, chargingStation: ChargingStation, connector: Connector, options: { countryID: string; partyID: string; addChargeBoxID?: boolean}): OICPEvseStatusRecord {
const evseStatus: OICPEvseStatusRecord = {} as OICPEvseStatusRecord;
- evseStatus.EvseID = RoamingUtils.buildEvseID(options.countryID, options.partyID, chargingStation, connector);
+ evseStatus.EvseID = RoamingUtils.buildEvseID(options.countryID, options.partyID, chargingStation.id, connector.connectorId);
evseStatus.EvseStatus = OICPMapping.convertStatus2OICPEvseStatus(connector.status);
evseStatus.ChargingStationID = chargingStation.id;
return evseStatus;
@@ -410,7 +410,7 @@ export default class OICPMapping {
const evse: OICPEvseDataRecord = {} as OICPEvseDataRecord;
evse.deltaType; // Optional
evse.lastUpdate; // Optional
- evse.EvseID = RoamingUtils.buildEvseID(options.countryID, options.partyID, chargingStation, connector);
+ evse.EvseID = RoamingUtils.buildEvseID(options.countryID, options.partyID, chargingStation.id, connector.connectorId);
evse.ChargingPoolID = OICPMapping.buildEChargingPoolID(options.countryID, options.partyID, siteArea.id); // Optional
evse.ChargingStationID = chargingStation.id; // Optional
evse.ChargingStationNames = [

MODIFY
src/storage/mongodb/ChargingStationStorage.ts
src/storage/mongodb/ChargingStationStorage.ts
@@ -143,23 +143,20 @@ export default class ChargingStationStorage {
return chargingStationsMDB.count === 1 ? chargingStationsMDB.result[0] : null;
}
- public static async getChargingStationBySerialNumber(tenantID: string, chargingStationSerialNumber: string = Constants.UNKNOWN_STRING_ID,
- params: { includeDeleted?: boolean, issuer?: boolean; } = {}, projectFields?: string[]): Promise<ChargingStation> {
+ public static async getChargingStationByOcpiEvseID(tenantID: string, ocpiEvseID: string = Constants.UNKNOWN_STRING_ID,
+ projectFields?: string[]): Promise<ChargingStation> {
const chargingStationsMDB = await ChargingStationStorage.getChargingStations(tenantID, {
- chargingStationSerialNumbers: [chargingStationSerialNumber],
- withSite: true,
- includeDeleted: params.includeDeleted,
- issuer: params.issuer,
+ ocpiEvseID,
}, Constants.DB_PARAMS_SINGLE_RECORD, projectFields);
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> {
+ 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;
}
@@ -167,7 +164,7 @@ export default class ChargingStationStorage {
public static async getChargingStations(tenantID: string,
params: {
search?: string; chargingStationIDs?: string[]; chargingStationSerialNumbers?: string[]; siteAreaIDs?: string[]; withNoSiteArea?: boolean;
- connectorStatuses?: string[]; connectorTypes?: string[]; statusChangedBefore?: Date; ocpiUid?: string;
+ connectorStatuses?: string[]; connectorTypes?: string[]; statusChangedBefore?: Date; ocpiUid?: string; ocpiEvseID?: string;
siteIDs?: string[]; withSite?: boolean; includeDeleted?: boolean; offlineSince?: Date; issuer?: boolean;
locCoordinates?: number[]; locMaxDistanceMeters?: number; public?: boolean;
},
@@ -232,6 +229,10 @@ export default class ChargingStationStorage {
if (params.ocpiUid) {
filters['ocpiData.evses.uid'] = params.ocpiUid;
}
+ // OCPI Evse ID
+ if (params.ocpiEvseID) {
+ filters['ocpiData.evses.evse_id'] = params.ocpiEvseID;
+ }
// Filter on lastSeen
if (params.offlineSince && moment(params.offlineSince).isValid()) {
filters.lastSeen = { $lte: params.offlineSince };

MODIFY
src/storage/mongodb/TransactionStorage.ts
src/storage/mongodb/TransactionStorage.ts
@@ -937,12 +937,14 @@ export default class TransactionStorage {
}
public static async getOCPITransaction(tenantID: string, sessionID: string): Promise<Transaction> {
- const transactionsMDB = await TransactionStorage.getTransactions(tenantID, { ocpiSessionID: sessionID }, Constants.DB_PARAMS_SINGLE_RECORD);
+ const transactionsMDB = await TransactionStorage.getTransactions(tenantID,
+ { ocpiSessionID: sessionID }, Constants.DB_PARAMS_SINGLE_RECORD);
return transactionsMDB.count === 1 ? transactionsMDB.result[0] : null;
}
public static async getOICPTransaction(tenantID: string, sessionID: string): Promise<Transaction> {
- const transactionsMDB = await TransactionStorage.getTransactions(tenantID, { oicpSessionID: sessionID }, Constants.DB_PARAMS_SINGLE_RECORD);
+ const transactionsMDB = await TransactionStorage.getTransactions(tenantID,
+ { oicpSessionID: sessionID }, Constants.DB_PARAMS_SINGLE_RECORD);
return transactionsMDB.count === 1 ? transactionsMDB.result[0] : null;
}

MODIFY
src/utils/RoamingUtils.ts
src/utils/RoamingUtils.ts
-import ChargingStation, { Connector } from '../types/ChargingStation';
-
import { EvseIdComponents } from '../types/oicp/OICPEvse';
export default class RoamingUtils {
@@ -8,17 +6,9 @@ export default class RoamingUtils {
return `${countryCode}*${partyId}`;
}
- /**
- * Build evse_id from charging station
- *
- * @param {*} countryCode the code of the CPO
- * @param {*} partyId the partyId of the CPO
- * @param {*} chargingStation the charging station used to build the evse ID
- * @param {*} connector the connector used to build the evse ID
- */
- public static buildEvseID(countryCode: string, partyId: string, chargingStation: ChargingStation, connector: Connector): string {
+ public static buildEvseID(countryCode: string, partyId: string, chargingStationID: string, connectorID: number): string {
// Format follows the eMI3 string format for EVSE: https://emi3group.com/wp-content/uploads/sites/5/2018/12/eMI3-standard-v1.0-Part-2.pdf
- const evseID = `${RoamingUtils.buildOperatorName(countryCode, partyId)}*E${chargingStation.id}*${connector.connectorId}`;
+ const evseID = `${RoamingUtils.buildOperatorName(countryCode, partyId)}*E${chargingStationID}*${connectorID}`;
return evseID.replace(/[\W_]+/g, '*').toUpperCase();
}

Check Emsp endpoint