Added car connector settings method, fixed tronity config
MODIFY
src/integration/car-connector/CarConnectorFactory.ts
src/integration/car-connector/CarConnectorFactory.ts
@@ -15,7 +15,7 @@ export default class CarConnectorFactory {
if (settings?.carConnector?.connections) {
// Find connection
// Vehicle make will be replaced with specific car information in the car object --> coming with Tronity
- const foundConnection = settings.carConnector.connections.find((connection) => connection.type === connectorId);
+ const foundConnection = settings.carConnector.connections.find((connection) => connection.id === connectorId);
if (foundConnection) {
let carConnectorIntegrationImpl: CarConnectorIntegration<CarConnectorSettings> = null;
switch (foundConnection.type) {

MODIFY
src/integration/car-connector/tronity-connector/TronityCarConnectorIntegration.ts
src/integration/car-connector/tronity-connector/TronityCarConnectorIntegration.ts
@@ -19,61 +19,11 @@ const MODULE_NAME = 'TronityCarConnectorIntegration';
export default class TronityCarConnectorIntegration extends CarConnectorIntegration<CarConnectorSettings> {
private axiosInstance: AxiosInstance;
- private readonly axiosRetryConfiguration: IAxiosRetryConfig = {
- retries: 3,
- retryCondition: (error) => error.response.status === StatusCodes.INTERNAL_SERVER_ERROR || axiosRetry.isNetworkError(error),
- retryDelay: (retryCount, error) => {
- try {
- if (error.config.method === 'post') {
- if (error.config.url.endsWith('/token.oauth2')) {
- throw new BackendError({
- source: Constants.CENTRAL_SERVER,
- module: MODULE_NAME,
- method: 'retryDelay',
- message: `Unable to post token, response status ${error.response.status}, attempt ${retryCount}`,
- action: ServerAction.CAR_CONNECTOR,
- detailedMessages: { response: error.response }
- });
- } else {
- const payload = {
- error: error.response.data,
- payload: JSON.parse(error.config.data)
- };
- throw new BackendError({
- source: Constants.CENTRAL_SERVER,
- module: MODULE_NAME,
- method: 'retryDelay',
- message: `Unable to post data on ${error.config.url}, response status ${error.response.status}, attempt ${retryCount}`,
- action: ServerAction.CAR_CONNECTOR,
- detailedMessages: { payload }
- });
- }
- } else {
- throw new BackendError({
- source: Constants.CENTRAL_SERVER,
- module: MODULE_NAME,
- method: 'retryDelay',
- message: `Unable to make data request on ${error.config.url}, response status ${error.response.status}, attempt ${retryCount}`,
- action: ServerAction.CAR_CONNECTOR,
- detailedMessages: { response: error.response.data }
- });
- }
- } catch (err) {
- void Logging.logException(
- err, ServerAction.CAR_CONNECTOR, Constants.CENTRAL_SERVER, MODULE_NAME, 'anonymous', this.tenant.id, null);
- }
- return axiosRetry.exponentialDelay(retryCount);
- },
- shouldResetTimeout: true
- };
constructor(tenant: Tenant, settings: CarConnectorSettings, connection: CarConnectorConnectionSetting) {
super(tenant, settings, connection);
// Get Axios
- this.axiosInstance = AxiosFactory.getAxiosInstance(this.tenant.id,
- {
- axiosRetryConfig: this.axiosRetryConfiguration,
- });
+ this.axiosInstance = AxiosFactory.getAxiosInstance(this.tenant.id);
}
public async connect(): Promise<string> {
@@ -90,7 +40,7 @@ export default class TronityCarConnectorIntegration extends CarConnectorIntegrat
public async getCurrentSoC(userID: string, car: Car): Promise<number> {
const connectionToken = await this.connect();
- const request = `${this.connection.tronityConnection.apiUrl}/`;
+ const request = `${this.connection.tronityConnection.apiUrl}/v1/vehicles/${car.carConnectorData.carConnectorMeterID}/battery`;
try {
// Get consumption
const response = await this.axiosInstance.get(
@@ -107,8 +57,8 @@ export default class TronityCarConnectorIntegration extends CarConnectorIntegrat
module: MODULE_NAME, method: 'getCurrentSoC',
detailedMessages: { response: response.data }
});
- if (response?.data?.soc?.value) {
- return response.data.soc.value;
+ if (response?.data?.level) {
+ return response.data.level;
}
return null;
} catch (error) {
@@ -146,13 +96,13 @@ export default class TronityCarConnectorIntegration extends CarConnectorIntegrat
expires: data['.expires']
};
this.connection.token = token;
- await SettingStorage.saveSettings(this.tenant, this.settings);
+ await SettingStorage.saveCarConnectorSettings(this.tenant, this.settings);
return token;
}
private buildFormHeaders(): any {
return {
- 'Content-Type': 'application/x-www-form-urlencoded'
+ 'Content-Type': 'application/json'
};
}
@@ -168,11 +118,11 @@ export default class TronityCarConnectorIntegration extends CarConnectorIntegrat
}
}
- private async getCredentialURLParams(): Promise<URLSearchParams> {
- const params = new URLSearchParams();
- params.append('grant_type', 'app');
- params.append('client_id', this.connection.tronityConnection.clientId);
- params.append('client_secret', await Cypher.decrypt(this.tenant, this.connection.tronityConnection.clientSecret));
- return params;
+ private async getCredentialURLParams(): Promise<any> {
+ return {
+ 'grant_type': 'app',
+ 'client_id': this.connection.tronityConnection.clientId,
+ 'client_secret': await Cypher.decrypt(this.tenant, this.connection.tronityConnection.clientSecret)
+ };
}
}

MODIFY
src/server/ocpp/services/OCPPService.ts
src/server/ocpp/services/OCPPService.ts
@@ -1789,7 +1789,7 @@ export default class OCPPService {
transaction.carID = user.lastSelectedCarID;
} else {
// Get default car if any
- const defaultCar = await CarStorage.getDefaultUserCar(tenant, user.id, {}, ['id', 'carCatalogID', 'vin', 'carCatalog.vehicleMake']);
+ const defaultCar = await CarStorage.getDefaultUserCar(tenant, user.id, {}, ['id', 'carCatalogID', 'vin', 'carConnectorData.carConnectorID', 'carConnectorData.carConnectorMeterID']);
if (defaultCar) {
transaction.carID = defaultCar.id;
transaction.carCatalogID = defaultCar.carCatalogID;
@@ -1798,7 +1798,7 @@ export default class OCPPService {
}
// Set Car Catalog ID
if (transaction.carID && !transaction.carCatalogID) {
- const car = await CarStorage.getCar(tenant, transaction.carID, {}, ['id', 'carCatalogID', 'vin', 'carCatalog.vehicleMake']);
+ const car = await CarStorage.getCar(tenant, transaction.carID, {}, ['id', 'carCatalogID', 'vin', 'carConnectorData.carConnectorID', 'carConnectorData.carConnectorMeterID']);
transaction.carCatalogID = car?.carCatalogID;
transaction.car = car;
}
@@ -1828,8 +1828,8 @@ export default class OCPPService {
private async getCurrentSoc(tenant: Tenant, transaction: Transaction, chargingStation: ChargingStation): Promise<number> {
if (Utils.isTenantComponentActive(tenant, TenantComponents.CAR_CONNECTOR) && !Utils.isNullOrUndefined(transaction.car) &&
- Utils.getChargingStationCurrentType(chargingStation, null, transaction.connectorId) === CurrentType.AC) {
- const carImplementation = await CarConnectorFactory.getCarConnectorImpl(tenant, transaction.car?.carCatalog?.vehicleMake?.toLowerCase());
+ !Utils.isNullOrUndefined(transaction.car.carConnectorData) && Utils.getChargingStationCurrentType(chargingStation, null, transaction.connectorId) === CurrentType.AC) {
+ const carImplementation = await CarConnectorFactory.getCarConnectorImpl(tenant, transaction.car.carConnectorData?.carConnectorID);
if (carImplementation) {
try {
return await carImplementation.getCurrentSoC(transaction.userID, transaction.car);

MODIFY
src/storage/mongodb/SettingStorage.ts
src/storage/mongodb/SettingStorage.ts
-import { AnalyticsSettings, AnalyticsSettingsType, AssetSettings, AssetSettingsType, BillingSetting, BillingSettings, BillingSettingsType, CarConnectorSettings, CarConnectorSettingsType, CryptoSetting, CryptoSettings, CryptoSettingsType, PricingSettings, PricingSettingsType, RefundSettings, RefundSettingsType, RoamingSettings, SettingDB, SmartChargingSettings, SmartChargingSettingsType, TechnicalSettings, UserSettings, UserSettingsType } from '../../types/Setting';
+import { AnalyticsSettings, AnalyticsSettingsType, AssetSettings, AssetSettingsType, BillingSetting, BillingSettings, BillingSettingsType, CarConnectorSetting, CarConnectorSettings, CarConnectorSettingsType, CryptoSetting, CryptoSettings, CryptoSettingsType, PricingSettings, PricingSettingsType, RefundSettings, RefundSettingsType, RoamingSettings, SettingDB, SmartChargingSettings, SmartChargingSettingsType, TechnicalSettings, UserSettings, UserSettingsType } from '../../types/Setting';
import Tenant, { TenantComponents } from '../../types/Tenant';
import global, { FilterParams } from '../../types/GlobalType';
@@ -214,6 +214,18 @@ export default class SettingStorage {
return carConnectorSettings;
}
+ public static async saveCarConnectorSettings(tenant: Tenant, carConnectorSettings: CarConnectorSettings): Promise<string> {
+ const { id, identifier, backupSensitiveData, sensitiveData } = carConnectorSettings;
+ const setting: SettingDB = {
+ id, identifier, sensitiveData, backupSensitiveData,
+ content: {
+ type: carConnectorSettings.type,
+ carConnector: carConnectorSettings.carConnector,
+ },
+ };
+ return SettingStorage.saveSettings(tenant, setting);
+ }
+
public static async getPricingSettings(tenant: Tenant, limit?: number, skip?: number, dateFrom?: Date, dateTo?: Date): Promise<PricingSettings> {
const pricingSettings = {
identifier: TenantComponents.PRICING,

Added car connector settings method, fixed tronity config