Skip to content

armgit / core

Public Imported from GitHub
0

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

get units from util

Vincent79c714c08079
diff --git a/ui/component/or-attribute-card/src/index.ts b/ui/component/or-attribute-card/src/index.ts
index 22a8c6917..5c9dcb387 100644
--- a/ui/component/or-attribute-card/src/index.ts
+++ b/ui/component/or-attribute-card/src/index.ts
@@ -2,7 +2,7 @@ import {css, customElement, html, LitElement, property, PropertyValues, query, u
import {classMap} from "lit-html/directives/class-map";
import i18next from "i18next";
import {Asset, AssetAttribute, Attribute, DatapointInterval, MetaItemType, ValueDatapoint} from "@openremote/model";
-import {manager, DefaultColor3, DefaultColor4, DefaultColor5, Util} from "@openremote/core";
+import {manager, DefaultColor3, DefaultColor4, DefaultColor5, Util, AssetModelUtil} from "@openremote/core";
import Chart, {ChartTooltipCallback} from "chart.js";
import {getContentWithMenuTemplate, OrChartConfig} from "@openremote/or-chart";
import {InputType} from "@openremote/or-input";
@@ -647,13 +647,15 @@ export class OrAttributeCard extends LitElement {
protected getFormattedValue(value: number): {value: number, unit: string, formattedValue: string} {
const format = getMetaValue(MetaItemType.FORMAT, this.asset.attributes![this.attributeName!], undefined);
+ const attr = this.asset.attributes![this.attributeName!];
const roundedVal = +value.toFixed(1); // + operator prevents str return
- if (!format) {
- return {value: roundedVal, unit: "", formattedValue: value.toString()};
- }
+ const attributeDescriptor = AssetModelUtil.getAttributeDescriptorFromAsset(this.attributeName!);
+ const unit = Util.getMetaValue(MetaItemType.UNIT_TYPE, attr, attributeDescriptor);
+ let label = Util.getAttributeLabel(attr, attributeDescriptor);
+
+ if (!format) { return {value: roundedVal, unit: unit, formattedValue: roundedVal.toString()}; }
- const unit = format.split(" ").pop();
return {
value: roundedVal,
unit: unit,