Fixed creation of consumption
MODIFY
src/integration/asset/AssetIntegration.ts
src/integration/asset/AssetIntegration.ts
@@ -16,7 +16,6 @@ export default abstract class AssetIntegration<T extends AssetSetting> {
abstract checkConnection(): Promise<void>;
- abstract retrieveConsumption(asset: Asset): Promise<AbstractCurrentConsumption>;
+ abstract retrieveConsumption(asset: Asset, manualCall?: boolean): Promise<AbstractCurrentConsumption>;
- abstract createConsumption(asset: Asset, currentConsumption: AbstractCurrentConsumption): Consumption;
}

MODIFY
src/integration/asset/greencom/GreencomAssetIntegration.ts
src/integration/asset/greencom/GreencomAssetIntegration.ts
@@ -27,10 +27,12 @@ export default class GreencomAssetIntegration extends AssetIntegration<AssetSett
await this.connect();
}
- public async retrieveConsumption(asset: Asset): Promise<AbstractCurrentConsumption> {
+ public async retrieveConsumption(asset: Asset, manualCall: boolean): Promise<AbstractCurrentConsumption> {
// Set new Token
const token = await this.connect();
- const request = `${this.connection.url}/site-api/${asset.meterID}?withEnergy=true&withPower=true&from=${moment().subtract(1, 'minutes').toISOString()}&to=${moment().toISOString()}&step=PT1M`;
+ const request = manualCall ?
+ `${this.connection.url}/site-api/${asset.meterID}?withEnergy=true&withPower=true&from=${moment().subtract(1, 'minutes').toISOString()}&to=${moment().toISOString()}&step=PT1M` :
+ `${this.connection.url}/site-api/${asset.meterID}?withEnergy=true&withPower=true&from=${asset.lastConsumption.timestamp.toISOString()}&to=${moment().toISOString()}&step=PT1M`;
try {
// Get consumption
const response = await this.axiosInstance.get(
@@ -60,19 +62,6 @@ export default class GreencomAssetIntegration extends AssetIntegration<AssetSett
}
}
- public createConsumption(asset: Asset, currentConsumption: AbstractCurrentConsumption): Consumption {
- const consumption: Consumption = {
- startedAt: moment().subtract(1, 'minutes').toDate(),
- endedAt: new Date(),
- assetID: asset.id,
- cumulatedConsumptionWh: currentConsumption.currentConsumptionWh,
- cumulatedConsumptionAmps: currentConsumption.currentConsumptionWh,
- instantAmps: currentConsumption.currentInstantAmps,
- instantWatts: currentConsumption.currentInstantWatts
- };
- return consumption;
- }
-
private filterConsumptionRequest(asset: Asset, data: any): AbstractCurrentConsumption {
const consumption = {} as AbstractCurrentConsumption;
// Convert data
@@ -96,6 +85,13 @@ export default class GreencomAssetIntegration extends AssetIntegration<AssetSett
if (asset.siteArea?.voltage) {
consumption.currentInstantAmps = consumption.currentInstantWatts / asset.siteArea.voltage;
}
+
+ // Set last consumption
+ consumption.lastConsumption = {
+ value: consumption.currentConsumptionWh,
+ timestamp: new Date()
+ };
+
return consumption;
}

MODIFY
src/integration/asset/schneider/SchneiderAssetIntegration.ts
src/integration/asset/schneider/SchneiderAssetIntegration.ts
@@ -59,18 +59,6 @@ export default class SchneiderAssetIntegration extends AssetIntegration<AssetSet
}
}
- public createConsumption(asset: Asset, currentConsumption: AbstractCurrentConsumption): Consumption {
- const consumption: Consumption = {
- startedAt: asset.lastConsumption.timestamp,
- endedAt: new Date(),
- assetID: asset.id,
- cumulatedConsumptionWh: currentConsumption.currentConsumptionWh,
- cumulatedConsumptionAmps: Math.floor(currentConsumption.currentConsumptionWh / 230),
- instantAmps: currentConsumption.currentInstantAmps,
- instantWatts: currentConsumption.currentInstantWatts,
- };
- return consumption;
- }
private filterConsumptionRequest(asset: Asset, data: any[]): AbstractCurrentConsumption {
const consumption = {} as AbstractCurrentConsumption;

MODIFY
src/scheduler/tasks/AssetGetConsumptionTask.ts
src/scheduler/tasks/AssetGetConsumptionTask.ts
@@ -41,8 +41,15 @@ export default class AssetGetConsumptionTask extends SchedulerTask {
// Retrieve Consumption
const assetConsumption = await assetImpl.retrieveConsumption(asset);
// Create Consumption to save
- // Needs to be implemented separately, because of different timestamp handling
- const consumption = assetImpl.createConsumption(asset, assetConsumption);
+ const consumption: Consumption = {
+ startedAt: asset.lastConsumption.timestamp,
+ endedAt: new Date(),
+ assetID: asset.id,
+ cumulatedConsumptionWh: assetConsumption.currentConsumptionWh,
+ cumulatedConsumptionAmps: Math.floor(assetConsumption.currentConsumptionWh / asset.siteArea.voltage),
+ instantAmps: assetConsumption.currentInstantAmps,
+ instantWatts: assetConsumption.currentInstantWatts,
+ };
// Set Consumption to Asset
this.assignAssetConsumption(asset, assetConsumption);
// Save Asset

MODIFY
src/server/rest/v1/service/AssetService.ts
src/server/rest/v1/service/AssetService.ts
@@ -176,7 +176,7 @@ export default class AssetService {
});
}
// Retrieve consumption
- const consumption = await assetImpl.retrieveConsumption(asset);
+ const consumption = await assetImpl.retrieveConsumption(asset, true);
// Assign
asset.lastConsumption = consumption.lastConsumption;
asset.currentConsumptionWh = consumption.currentConsumptionWh;

Fixed creation of consumption