Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

retrieve datapoints and stub them

Vincente7041c3fe0d9
diff --git a/ui/component/or-attribute-card/src/index.ts b/ui/component/or-attribute-card/src/index.ts
index a7c35a5fd..48873b2ac 100644
--- a/ui/component/or-attribute-card/src/index.ts
+++ b/ui/component/or-attribute-card/src/index.ts
@@ -53,6 +53,9 @@ export class OrAttributeCard extends LitElement {
@property()
public attributeName: string = "";
+ @property()
+ protected _data?: ValueDatapoint<any>[] = [{x: 1587333600000, y: 0}, {x: 1587337200000, y: 8.99}, {x: 1587340800000, y: 0}, {x: 1587344400000, y: 0}, {x: 1587348000000, y: 0}, {x: 1587351600000, y: 0}, {x: 1587355200000, y: 9.11}, {x: 1587358800000, y: 0}, {x: 1587362400000, y: 0}, {x: 1587366000000, y: 10.22}, {x: 1587369600000, y: 11.385}, {x: 1587373200000, y: 12.16875}, {x: 1587376800000, y: 0}, {x: 1587380400000, y: 0}, {x: 1587384000000, y: 0}, {x: 1587387600000, y: 0}, {x: 1587391200000, y: 0}, {x: 1587394800000, y: 0}, {x: 1587398400000, y: 0}, {x: 1587402000000, y: 0}, {x: 1587405600000, y: 0}, {x: 1587409200000, y: 0}, {x: 1587412800000, y: 0}, {x: 1587416400000, y: 0}];
+
@property()
private cardTitle: string = "";
@@ -69,6 +72,12 @@ export class OrAttributeCard extends LitElement {
this.getAssetById(this.assetId)
.then((data) => {
this.assetName = data.name || "";
+ if (data.id) {
+ this.getDatapointsByAttribute(data.id)
+ .then((datapoints: any) => { // todo: fix this any
+ // this._data = datapoints;
+ });
+ }
}
);
};
@@ -120,4 +129,26 @@ export class OrAttributeCard extends LitElement {
return response.data[0];
}
+ // todo: get rid of this <any>
+ private async getDatapointsByAttribute(id: string): Promise<ValueDatapoint<any>[]> {
+ const response = await manager.rest.api.AssetDatapointResource.getDatapoints(
+ id,
+ this.attributeName,
+ {
+ interval: DatapointInterval.DAY,
+ fromTimestamp: 1585692000000,
+ toTimestamp: 1588283999999
+ }
+ );
+ // vars 2U48805AfxblLl1P5dCifA light1PowerConsumption 1585692000000 1588283999999 DAY string
+ // 1585692000000 1588283999999 DAY
+ console.log("data", response);
+
+ if (response.status !== 200 || !response.data) {
+ return [];
+ }
+
+ return response.data;
+ }
+
}