Fixed last consumption based on extra inactivity
MODIFY
src/server/ocpp/services/OCPPService.ts
src/server/ocpp/services/OCPPService.ts
@@ -191,7 +191,7 @@ export default class OCPPService {
return {};
}
// Update only the given Connector ID
- await this.updateConnectorStatusFromStatusNotification(tenant, chargingStation, statusNotification);
+ await this.processConnectorStatusNotification(tenant, chargingStation, statusNotification);
return {};
} catch (error) {
this.addChargingStationToException(error, headers.chargeBoxIdentity);
@@ -651,7 +651,7 @@ export default class OCPPService {
}
}
- private async updateConnectorStatusFromStatusNotification(tenant: Tenant, chargingStation: ChargingStation, statusNotification: OCPPStatusNotificationRequestExtended) {
+ private async processConnectorStatusNotification(tenant: Tenant, chargingStation: ChargingStation, statusNotification: OCPPStatusNotificationRequestExtended) {
// Get Connector
const connector = await this.checkAndGetConnectorFromStatusNotification(tenant, chargingStation, statusNotification);
// Status must be different

MODIFY
src/server/ocpp/utils/OCPPUtils.ts
src/server/ocpp/utils/OCPPUtils.ts
@@ -151,8 +151,8 @@ export default class OCPPUtils {
if (lastConsumption) {
delete lastConsumption.id;
// Create the extra consumption with inactivity
- lastConsumption.startedAt = lastConsumption.endedAt;
- lastConsumption.endedAt = moment(lastConsumption.startedAt).add(transaction.stop.extraInactivitySecs, 's').toDate();
+ lastConsumption.startedAt = transaction.stop.timestamp;
+ lastConsumption.endedAt = moment(transaction.stop.timestamp).add(transaction.stop.extraInactivitySecs, 's').toDate();
// Set inactivity
lastConsumption.consumptionAmps = 0;
lastConsumption.consumptionWh = 0;
@@ -170,7 +170,8 @@ export default class OCPPUtils {
await ConsumptionStorage.saveConsumption(tenant.id, lastConsumption);
// Update the Stop transaction data
transaction.stop.timestamp = lastConsumption.endedAt;
- transaction.stop.totalDurationSecs = Math.floor((transaction.stop.timestamp.getTime() - transaction.timestamp.getTime()) / 1000);
+ transaction.stop.totalDurationSecs = Utils.createDecimal(
+ Math.floor((transaction.stop.timestamp.getTime() - transaction.timestamp.getTime()))).div(1000).toNumber();
transaction.stop.extraInactivityComputed = true;
return true;
}

Fixed last consumption based on extra inactivity