Fixed unit test + add logs
MODIFY
src/scheduler/tasks/CheckOfflineChargingStationsTask.ts
src/scheduler/tasks/CheckOfflineChargingStationsTask.ts
-import moment from 'moment';
import ChargingStationClientFactory from '../../client/ocpp/ChargingStationClientFactory';
-import LockingManager from '../../locking/LockingManager';
-import NotificationHandler from '../../notification/NotificationHandler';
import ChargingStationStorage from '../../storage/mongodb/ChargingStationStorage';
+import { CheckOfflineChargingStationsTaskConfig } from '../../types/TaskConfig';
+import Constants from '../../utils/Constants';
import { LockEntity } from '../../types/Locking';
+import LockingManager from '../../locking/LockingManager';
+import Logging from '../../utils/Logging';
+import NotificationHandler from '../../notification/NotificationHandler';
import { OCPPGetConfigurationCommandResult } from '../../types/ocpp/OCPPClient';
+import SchedulerTask from '../SchedulerTask';
import { ServerAction } from '../../types/Server';
-import { CheckOfflineChargingStationsTaskConfig } from '../../types/TaskConfig';
import Tenant from '../../types/Tenant';
-import Constants from '../../utils/Constants';
-import Logging from '../../utils/Logging';
import Utils from '../../utils/Utils';
-import SchedulerTask from '../SchedulerTask';
+import moment from 'moment';
export default class CheckOfflineChargingStationsTask extends SchedulerTask {
@@ -29,20 +29,29 @@ export default class CheckOfflineChargingStationsTask extends SchedulerTask {
}, Constants.DB_PARAMS_MAX_LIMIT);
if (chargingStations.count > 0) {
for (let i = chargingStations.result.length - 1; i >= 0; i--) {
+ const chargingStation = chargingStations.result[i];
let configuration: OCPPGetConfigurationCommandResult;
// Check if charging station is still connected
try {
- const chargingStationClient = await ChargingStationClientFactory.getChargingStationClient(tenant.id, chargingStations.result[i]);
+ const chargingStationClient = await ChargingStationClientFactory.getChargingStationClient(tenant.id, chargingStation);
if (chargingStationClient) {
configuration = await chargingStationClient.getConfiguration({});
}
} catch (error) {
+ // Charging Station is offline!
continue;
}
// Charging Station is still connected: ignore it
if (configuration) {
+ Logging.logInfo({
+ tenantID: tenant.id,
+ source: chargingStation.id,
+ action: ServerAction.MIGRATION,
+ module: MODULE_NAME, method: 'processTenant',
+ message: 'Offline charging station responded successfuly to an OCPP command and will be ignored',
+ });
// Update Heartbeat
- await ChargingStationStorage.saveChargingStationHeartBeat(tenant.id, chargingStations.result[i].id,
+ await ChargingStationStorage.saveChargingStationHeartBeat(tenant.id, chargingStation.id,
{ lastHeartBeat: new Date() }
);
// Remove charging station from notification

MODIFY
test/api/OCPPCommonTests.ts
test/api/OCPPCommonTests.ts
@@ -642,11 +642,9 @@ export default class OCPPCommonTests {
const transactionCurrentTime = moment(this.newTransaction.timestamp);
let transactionCumulatedConsumption = this.energyActiveImportStartMeterValue;
// Check Consumption
- for (let i = 0; i < response.data.values.length; i++) {
+ for (let i = 0; i < response.data.values.length - 1; i++) {
// Get the value
const value = response.data.values[i];
- // Add time
- transactionCurrentTime.add(this.meterValueIntervalSecs, 's');
// Sum
transactionCumulatedConsumption += this.energyActiveImportMeterValues[i];
// Check
@@ -688,6 +686,8 @@ export default class OCPPCommonTests {
null, this.newTransaction.connectorId, transactionCumulatedConsumption)
});
}
+ // Add time
+ transactionCurrentTime.add(this.meterValueIntervalSecs, 's');
}
}

Fixed unit test + add logs