Fixed Cannot read 'lastConsumption' of undefined
MODIFY
src/scheduler/tasks/AssetGetConsumptionTask.ts
src/scheduler/tasks/AssetGetConsumptionTask.ts
@@ -41,12 +41,9 @@ export default class AssetGetConsumptionTask extends SchedulerTask {
if (assetImpl) {
// Retrieve Consumption
const assetConsumptions = await assetImpl.retrieveConsumptions(asset);
+ if (!Utils.isEmptyArray(assetConsumptions)) {
// Create helper for site area limit
- const siteAreaLimitConsumption: Consumption = {
- startedAt: assetConsumptions[0].lastConsumption.timestamp,
- cumulatedConsumptionWh: assetConsumptions[0].currentConsumptionWh,
- cumulatedConsumptionAmps: Math.floor(assetConsumptions[0].currentConsumptionWh / asset.siteArea.voltage),
- };
+ const siteAreaLimitConsumption = {} as Consumption;
await OCPPUtils.addSiteLimitationToConsumption(tenant.id, asset.siteArea, siteAreaLimitConsumption);
// Create Consumptions
for (const consumption of assetConsumptions) {
@@ -79,6 +76,7 @@ export default class AssetGetConsumptionTask extends SchedulerTask {
// Save Asset
await AssetStorage.saveAsset(tenant.id, asset);
}
+ }
} catch (error) {
// Log error
await Logging.logActionExceptionMessage(tenant.id, ServerAction.RETRIEVE_ASSET_CONSUMPTION, error);

Fixed Cannot read 'lastConsumption' of undefined