handle soc when meter value is received
MODIFY
src/integration/car-connector/mercedes-connector/MercedesCarConnectorIntegration.ts
src/integration/car-connector/mercedes-connector/MercedesCarConnectorIntegration.ts
@@ -148,7 +148,18 @@ export default class MercedesCarConnectorIntegration extends CarConnectorIntegra
headers: { 'Authorization': 'Bearer ' + connection.data.access_token }
}
);
- return response.data.soc;
+ await Logging.logDebug({
+ tenantID: this.tenant.id,
+ source: Constants.CENTRAL_SERVER,
+ action: ServerAction.CAR_CONNECTOR,
+ message: `${VIN} > Mercedes web service has been called successfully`,
+ module: MODULE_NAME, method: 'getCurrentSoC',
+ detailedMessages: { response: response.data }
+ });
+ if (response?.data?.soc?.value) {
+ return response.data.soc.value;
+ }
+ return null;
} catch (error) {
throw new BackendError({
source: Constants.CENTRAL_SERVER,

MODIFY
src/server/ocpp/services/OCPPService.ts
src/server/ocpp/services/OCPPService.ts
@@ -253,6 +253,8 @@ export default class OCPPService {
this.updateTransactionWithMeterValues(chargingStation, transaction, normalizedMeterValues.values);
// Create Consumptions
const consumptions = await OCPPUtils.createConsumptionsFromMeterValues(tenant, chargingStation, transaction, normalizedMeterValues.values);
+ // Handle current SOC
+ consumptions[consumptions.length - 1].stateOfCharge = await this.getCurrentSOC(tenant, transaction, chargingStation);
// Price/Bill Transaction and Save them
for (const consumption of consumptions) {
// Update Transaction with Consumption
@@ -1699,22 +1701,23 @@ export default class OCPPService {
Utils.getChargingStationCurrentType(chargingStation, null, transaction.connectorId) === CurrentType.AC) {
const car = await CarStorage.getCar(tenant, transaction.carID);
const carCatalog = await CarStorage.getCarCatalog(car.carCatalogID);
- let stateOfCharge = 0;
+ // TBD: Instead of using make --> change the identification of the car connector to specific connector data in the car object
+ // Will be implemented with the Tronity integration
switch (carCatalog.vehicleMake) {
case 'Mercedes': {
const carImplementation = await CarConnectorFactory.getCarConnectorImpl(tenant, CarConnectorConnectionType.MERCEDES);
if (carImplementation) {
try {
- stateOfCharge = await carImplementation.getCurrentSoC(transaction.userID, car.vin);
+ return await carImplementation.getCurrentSoC(transaction.userID, car.vin);
} catch {
- return 0;
+ return null;
}
- return stateOfCharge;
}
break;
}
}
}
+ return null;
}
private addChargingStationToException(error: BackendError, chargingStationID: string): void {

MODIFY
src/server/ocpp/utils/OCPPUtils.ts
src/server/ocpp/utils/OCPPUtils.ts
@@ -877,6 +877,8 @@ export default class OCPPUtils {
for (const consumption of consumptions) {
OCPPUtils.assertConsistencyInConsumption(chargingStation, transaction.connectorId, consumption);
}
+ // Sort consumptions by date
+ consumptions.sort((a,b) => a.startedAt.getTime() - b.startedAt.getTime());
return consumptions;
}

MODIFY
src/storage/mongodb/ConsumptionStorage.ts
src/storage/mongodb/ConsumptionStorage.ts
@@ -677,7 +677,7 @@ export default class ConsumptionStorage {
instantVoltsDC: Utils.convertToFloat(consumption.instantVoltsDC),
totalInactivitySecs: Utils.convertToInt(consumption.totalInactivitySecs),
totalDurationSecs: Utils.convertToInt(consumption.totalDurationSecs),
- stateOfCharge: Utils.convertToInt(consumption.stateOfCharge),
+ stateOfCharge: !Utils.isNullOrUndefined(consumption.stateOfCharge) ? Utils.convertToInt(consumption.stateOfCharge) : null,
limitAmps: Utils.convertToInt(consumption.limitAmps),
limitWatts: Utils.convertToInt(consumption.limitWatts),
limitSource: consumption.limitSource,

handle soc when meter value is received