added refresh interval to asset connection
MODIFY
src/integration/asset/AssetIntegration.ts
src/integration/asset/AssetIntegration.ts
@@ -2,6 +2,7 @@ import { AssetConnectionSetting, AssetSetting } from '../../types/Setting';
import { AbstractCurrentConsumption } from '../../types/Consumption';
import Asset from '../../types/Asset';
+import moment from 'moment';
export default abstract class AssetIntegration<T extends AssetSetting> {
protected readonly tenantID: string;
@@ -14,7 +15,16 @@ export default abstract class AssetIntegration<T extends AssetSetting> {
this.connection = connection;
}
+ public checkIfIntervalExceeded(asset: Asset): boolean {
+ if (asset.lastConsumption?.timestamp && this.connection.refreshIntervalMins &&
+ moment() < moment(asset.lastConsumption.timestamp).add(this.connection.refreshIntervalMins, 'minutes')) {
+ return false;
+ }
+ return true;
+ }
+
abstract checkConnection(): Promise<void>;
abstract retrieveConsumptions(asset: Asset, manualCall?: boolean): Promise<AbstractCurrentConsumption[]>;
+
}

MODIFY
src/integration/asset/greencom/GreencomAssetIntegration.ts
src/integration/asset/greencom/GreencomAssetIntegration.ts
@@ -28,6 +28,10 @@ export default class GreencomAssetIntegration extends AssetIntegration<AssetSett
}
public async retrieveConsumptions(asset: Asset, manualCall?: boolean): Promise<AbstractCurrentConsumption[]> {
+ // Check if refresh interval of connection is exceeded
+ if (!manualCall && !this.checkIfIntervalExceeded(asset)) {
+ return [];
+ }
// Set new Token
const token = await this.connect();
const request = manualCall ?

MODIFY
src/integration/asset/iothink/IothinkAssetIntegration.ts
src/integration/asset/iothink/IothinkAssetIntegration.ts
@@ -29,6 +29,10 @@ export default class IothinkAssetIntegration extends AssetIntegration<AssetSetti
}
public async retrieveConsumptions(asset: Asset, manualCall: boolean): Promise<AbstractCurrentConsumption[]> {
+ // Check if refresh interval of connection is exceeded
+ if (!manualCall && !this.checkIfIntervalExceeded(asset)) {
+ return [];
+ }
// Set new Token
const token = await this.connect();
// Calculate timestamp of the last consumption in seconds from 1.1.2000, if not available get start of day

MODIFY
src/integration/asset/schneider/SchneiderAssetIntegration.ts
src/integration/asset/schneider/SchneiderAssetIntegration.ts
@@ -26,7 +26,11 @@ export default class SchneiderAssetIntegration extends AssetIntegration<AssetSet
await this.connect();
}
- public async retrieveConsumptions(asset: Asset): Promise<AbstractCurrentConsumption[]> {
+ public async retrieveConsumptions(asset: Asset, manualCall: boolean): Promise<AbstractCurrentConsumption[]> {
+ // Check if refresh interval of connection is exceeded
+ if (!manualCall && !this.checkIfIntervalExceeded(asset)) {
+ return [];
+ }
// Set new Token
const token = await this.connect();
const request = `${this.connection.url}/${asset.meterID}`;
@@ -38,7 +42,7 @@ export default class SchneiderAssetIntegration extends AssetIntegration<AssetSet
headers: this.buildAuthHeader(token)
}
);
- Logging.logDebug({
+ await Logging.logDebug({
tenantID: this.tenantID,
source: Constants.CENTRAL_SERVER,
action: ServerAction.RETRIEVE_ASSET_CONSUMPTION,

MODIFY
src/server/rest/v1/service/security/SettingSecurity.ts
src/server/rest/v1/service/security/SettingSecurity.ts
@@ -212,6 +212,7 @@ export default class SettingSecurity {
description: sanitize(connection.description),
url: sanitize(connection.url),
type: sanitize(connection.type),
+ refreshIntervalMins: sanitize(connection.refreshIntervalMins),
timestamp: new Date(),
};
// Check type

MODIFY
src/types/Setting.ts
src/types/Setting.ts
@@ -275,6 +275,7 @@ export interface AssetConnectionSetting {
url: string;
timestamp: Date;
type: AssetConnectionType;
+ refreshIntervalMins?: number;
schneiderConnection?: AssetSchneiderConnectionType;
greencomConnection?: AssetGreencomConnectionType;
iothinkConnection?: AssetIothinkConnectionType;

added refresh interval to asset connection