Added lastConsumptionWh property + filter consumption properties
MODIFY
src/integration/asset/schneider/SchneiderAssetIntegration.ts
src/integration/asset/schneider/SchneiderAssetIntegration.ts
@@ -40,12 +40,16 @@ export default class SchneiderAssetIntegration extends AssetIntegration<AssetSet
headers: this.buildAuthHeader()
}
);
- return this.filterEnergyConsumptionRequest(asset, data);
+ if (data && data.length > 0) {
+ return this.filterConsumptionRequest(asset, data);
+ }
+ return null;
}
- private filterEnergyConsumptionRequest(asset: Asset, data: any): AbstractConsumption {
+ private filterConsumptionRequest(asset: Asset, data: any): AbstractConsumption {
let consumption = {} as AbstractConsumption;
- consumption.consumptionWh = this.getLastConsumptionWh(asset, +data[0].Value);
+ consumption.consumptionWh = +data[0].Value * 1000;
+ consumption.lastConsumptionWh = this.getLastConsumptionWh(asset, +data[0].Value)
consumption.instantAmpsL1 = +data[6].Value;
consumption.instantAmpsL2 = +data[7].Value;
consumption.instantAmpsL3 = +data[8].Value;
@@ -74,7 +78,7 @@ export default class SchneiderAssetIntegration extends AssetIntegration<AssetSet
`Time out error (5s) when trying to test the connection URL '${this.connection.url}/GetToken'`
);
// Set Token
- if (data.access_token) {
+ if (data && data.length > 0 && data.access_token) {
this.token = data.access_token;
}
}
@@ -89,10 +93,10 @@ export default class SchneiderAssetIntegration extends AssetIntegration<AssetSet
private getLastConsumptionWh(asset: Asset, consumptionkWh: number): number {
const consumptionWh = consumptionkWh * 1000;
- if (asset.consumption.consumptionWh > consumptionWh) {
+ if (asset.consumption && consumptionWh > asset.consumption.consumptionWh) {
return consumptionWh - asset.consumption.consumptionWh;
}
- return asset.consumption.consumptionWh;
+ return 0;
}
private isAssetConnectionInitialized(): void {

MODIFY
src/server/rest/service/AssetService.ts
src/server/rest/service/AssetService.ts
@@ -285,7 +285,7 @@ export default class AssetService {
withNoSiteArea: filteredRequest.WithNoSiteArea
},
{ limit: filteredRequest.Limit, skip: filteredRequest.Skip, sort: filteredRequest.Sort, onlyRecordCount: filteredRequest.OnlyRecordCount },
- [ 'id', 'name', 'siteAreaID', 'siteArea.id', 'siteArea.name', 'siteArea.siteID', 'assetType', 'coordinates', 'dynamicAsset', 'assetConnectionID', 'meterID']
+ [ 'id', 'name', 'siteAreaID', 'siteArea.id', 'siteArea.name', 'siteArea.siteID', 'assetType', 'coordinates', 'dynamicAsset', 'connectionID', 'meterID', 'consumption']
);
// Filter
AssetSecurity.filterAssetsResponse(assets, req.user);
@@ -381,6 +381,7 @@ export default class AssetService {
asset.dynamicAsset = filteredRequest.dynamicAsset;
asset.connectionID = filteredRequest.connectionID;
asset.meterID = filteredRequest.meterID;
+ asset.consumption = filteredRequest.consumption;
asset.lastChangedBy = { 'id': req.user.id };
asset.lastChangedOn = new Date();
// Update Asset

MODIFY
src/server/rest/service/security/AssetSecurity.ts
src/server/rest/service/security/AssetSecurity.ts
@@ -52,6 +52,7 @@ export default class AssetSecurity {
filteredRequest.assetType = sanitize(request.assetType),
filteredRequest.image = request.image;
filteredRequest.dynamicAsset = UtilsSecurity.filterBoolean(request.dynamicAsset);
+ filteredRequest.consumption = UtilsSecurity.filterAbstractConsumptionRequest(request.consumption);
if (request.coordinates && request.coordinates.length === 2) {
filteredRequest.coordinates = [
sanitize(request.coordinates[0]),
@@ -88,6 +89,7 @@ export default class AssetSecurity {
filteredAsset.dynamicAsset = asset.dynamicAsset;
filteredAsset.connectionID = asset.connectionID;
filteredAsset.meterID = asset.meterID;
+ filteredAsset.consumption = asset.consumption;
if (asset.siteArea) {
filteredAsset.siteArea = SiteAreaSecurity.filterSiteAreaResponse(asset.siteArea, loggedUser);
}

MODIFY
src/server/rest/service/security/UtilsSecurity.ts
src/server/rest/service/security/UtilsSecurity.ts
-import Address from '../../../../types/Address';
+import sanitize from 'mongo-sanitize';
import Authorizations from '../../../../authorization/Authorizations';
-import Constants from '../../../../utils/Constants';
+import Address from '../../../../types/Address';
+import { AbstractConsumption } from '../../../../types/Consumption';
import UserToken from '../../../../types/UserToken';
+import Constants from '../../../../utils/Constants';
import Utils from '../../../../utils/Utils';
-import sanitize from 'mongo-sanitize';
export default class UtilsSecurity {
static filterBoolean(value): boolean {
@@ -104,6 +105,27 @@ export default class UtilsSecurity {
}
}
+ static filterAbstractConsumptionRequest(consumption: AbstractConsumption): AbstractConsumption {
+ const filteredConsumption: AbstractConsumption = {} as AbstractConsumption;
+ if (consumption) {
+ filteredConsumption.consumptionWh = sanitize(consumption.consumptionWh);
+ filteredConsumption.instantAmpsL1 = sanitize(consumption.instantAmpsL1);
+ filteredConsumption.instantAmpsL2 = sanitize(consumption.instantAmpsL2);
+ filteredConsumption.instantAmpsL3 = sanitize(consumption.instantAmpsL3);
+ filteredConsumption.instantAmps = sanitize(consumption.instantAmps);
+ filteredConsumption.instantVoltsL1 = sanitize(consumption.instantVoltsL1);
+ filteredConsumption.instantVoltsL2 = sanitize(consumption.instantVoltsL2)
+ filteredConsumption.instantVoltsL3 = sanitize(consumption.instantVoltsL3);
+ filteredConsumption.instantVolts = sanitize(consumption.instantVolts);
+ filteredConsumption.instantWattsL1 = sanitize(consumption.instantWattsL1);
+ filteredConsumption.instantWattsL2 = sanitize(consumption.instantWattsL2);
+ filteredConsumption.instantWattsL3 = sanitize(consumption.instantWattsL3);
+ filteredConsumption.instantWatts = sanitize(consumption.instantWatts);
+ filteredConsumption.lastConsumptionWh = sanitize(consumption.lastConsumptionWh);
+ }
+ return filteredConsumption;
+ }
+
static filterAddressRequest(address: Address): Address {
const filteredAddress: Address = {} as Address;
if (address) {

MODIFY
src/types/Consumption.ts
src/types/Consumption.ts
@@ -18,6 +18,7 @@ export interface AbstractConsumption {
instantVoltsDC: number;
consumptionWh: number;
consumptionAmps: number;
+ lastConsumptionWh: number;
}
export default interface Consumption extends AbstractConsumption {

Added lastConsumptionWh property + filter consumption properties