Small issues tronity car connector
MODIFY
src/assets/server/rest/v1/schemas/car/car.json
src/assets/server/rest/v1/schemas/car/car.json
],
"properties": {
"carConnectorID": {
- "type": "string",
+ "type": ["string", "null"],
"sanitize": "mongo"
},
"carConnectorMeterID": {
- "type": "string",
+ "type": ["string", "null"],
"sanitize": "mongo"
}
}

MODIFY
src/integration/car-connector/CarConnectorFactory.ts
src/integration/car-connector/CarConnectorFactory.ts
@@ -8,14 +8,13 @@ import TronityCarConnectorIntegration from './tronity-connector/TronityCarConnec
import Utils from '../../utils/Utils';
export default class CarConnectorFactory {
- static async getCarConnectorImpl(tenant: Tenant, connectorId: string): Promise<CarConnectorIntegration<CarConnectorSettings>> {
+ static async getCarConnectorImpl(tenant: Tenant, carConnectorId: string): Promise<CarConnectorIntegration<CarConnectorSettings>> {
// Check if car connector component is active
if (Utils.isTenantComponentActive(tenant, TenantComponents.CAR_CONNECTOR)) {
const settings = await SettingStorage.getCarConnectorSettings(tenant);
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.id === connectorId);
+ // Find connection by id
+ const foundConnection = settings.carConnector.connections.find((connection) => connection.id === carConnectorId);
if (foundConnection) {
let carConnectorIntegrationImpl: CarConnectorIntegration<CarConnectorSettings> = null;
switch (foundConnection.type) {

MODIFY
src/integration/car-connector/CarConnectorIntegration.ts
src/integration/car-connector/CarConnectorIntegration.ts
import { CarConnectorConnectionSetting, CarConnectorConnectionToken, CarConnectorSettings } from '../../types/Setting';
import { Car } from '../../types/Car';
-import Connection from '../../types/Connection';
import Tenant from '../../types/Tenant';
import Utils from '../../utils/Utils';
@@ -19,12 +18,10 @@ export default abstract class CarConnectorIntegration<T extends CarConnectorSett
public checkIfTokenExpired(token: CarConnectorConnectionToken): boolean {
if (!Utils.isNullOrUndefined(token)) {
const expireTime = new Date(token.expires).getTime() - 60000; // 1 minute buffer
- const now = new Date().getTime();
- return expireTime <= now;
+ return expireTime <= new Date().getTime();
}
return true;
}
- public abstract getCurrentSoC(userID: string, car: Car): Promise<number>;
-
+ public abstract getCurrentSoC(car: Car, userID?: string): Promise<number>;
}

MODIFY
src/integration/car-connector/mercedes-connector/MercedesCarConnectorIntegration.ts
src/integration/car-connector/mercedes-connector/MercedesCarConnectorIntegration.ts
@@ -138,7 +138,7 @@ export default class MercedesCarConnectorIntegration extends CarConnectorIntegra
}
}
- public async getCurrentSoC(userID: string, car: Car): Promise<number> {
+ public async getCurrentSoC(car: Car, userID: string): Promise<number> {
const connection = await this.getRefreshedConnection(userID);
const request = `${this.connection.mercedesConnection.apiUrl}/vehicledata/v2/vehicles/${car.vin}/resources/soc`;
try {

MODIFY
src/integration/car-connector/tronity-connector/TronityCarConnectorIntegration.ts
src/integration/car-connector/tronity-connector/TronityCarConnectorIntegration.ts
import { CarConnectorConnectionSetting, CarConnectorConnectionToken, CarConnectorSettings } from '../../../types/Setting';
-import axiosRetry, { IAxiosRetryConfig } from 'axios-retry';
import AxiosFactory from '../../../utils/AxiosFactory';
import { AxiosInstance } from 'axios';
@@ -11,7 +10,6 @@ import Cypher from '../../../utils/Cypher';
import Logging from '../../../utils/Logging';
import { ServerAction } from '../../../types/Server';
import SettingStorage from '../../../storage/mongodb/SettingStorage';
-import { StatusCodes } from 'http-status-codes';
import Tenant from '../../../types/Tenant';
import Utils from '../../../utils/Utils';
@@ -38,7 +36,18 @@ export default class TronityCarConnectorIntegration extends CarConnectorIntegrat
return response.accessToken;
}
- public async getCurrentSoC(userID: string, car: Car): Promise<number> {
+ public async getCurrentSoC(car: Car): Promise<number> {
+ if (Utils.isNullOrUndefined(car.carConnectorData.carConnectorMeterID)) {
+ await Logging.logError({
+ tenantID: this.tenant.id,
+ source: Constants.CENTRAL_SERVER,
+ module: MODULE_NAME,
+ method: 'getCurrentSoC',
+ action: ServerAction.CAR_CONNECTOR,
+ message: `No Tronity meter id for > ${car.vin}`,
+ });
+ return null;
+ }
const connectionToken = await this.connect();
const request = `${this.connection.tronityConnection.apiUrl}/v1/vehicles/${car.carConnectorData.carConnectorMeterID}/battery`;
try {
@@ -57,7 +66,7 @@ export default class TronityCarConnectorIntegration extends CarConnectorIntegrat
module: MODULE_NAME, method: 'getCurrentSoC',
detailedMessages: { response: response.data }
});
- if (response?.data?.level) {
+ if (response.data?.level) {
return response.data.level;
}
return null;
@@ -87,13 +96,13 @@ export default class TronityCarConnectorIntegration extends CarConnectorIntegrat
`Time out error (5s) when getting the token with the connection URL '${this.connection.tronityConnection.apiUrl}/oauth/authentication'`
);
const data = response.data;
+ const currentTime = new Date();
const token : CarConnectorConnectionToken = {
accessToken: data.access_token,
tokenType: data.token_type,
expiresIn: data.expires_in,
- userName: data.userName,
- issued: data['.issued'],
- expires: data['.expires']
+ issued: currentTime,
+ expires: new Date(currentTime.getTime() + data.expires_in * 1000)
};
this.connection.token = token;
await SettingStorage.saveCarConnectorSettings(this.tenant, this.settings);

MODIFY
src/server/ocpp/services/OCPPService.ts
src/server/ocpp/services/OCPPService.ts
@@ -1828,11 +1828,12 @@ 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.isNullOrUndefined(transaction.car.carConnectorData) && Utils.getChargingStationCurrentType(chargingStation, null, transaction.connectorId) === CurrentType.AC) {
- const carImplementation = await CarConnectorFactory.getCarConnectorImpl(tenant, transaction.car.carConnectorData?.carConnectorID);
+ !Utils.isNullOrUndefined(transaction.car.carConnectorData?.carConnectorID) &&
+ 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);
+ return await carImplementation.getCurrentSoC(transaction.car, transaction.userID);
} catch {
return null;
}

MODIFY
src/types/Setting.ts
src/types/Setting.ts
@@ -359,11 +359,11 @@ export interface CarConnectorTronityConnectionType {
export interface CarConnectorConnectionToken {
accessToken: string,
+ expires: Date,
tokenType?: string,
expiresIn?: number,
userName?: string,
issued?: Date,
- expires: Date,
}
export enum CryptoSettingsType {

Small issues tronity car connector