Skip to content

Commit 33f0783

Browse files
author
David Buezas
committed
Fixed case when unit of measurement is missing. Added stub config
1 parent 27d42e7 commit 33f0783

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

dist/plotly-graph-card.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"start": "esbuild src/plotly-graph-card.ts --servedir=dist --outdir=dist --bundle --sourcemap=inline",
99
"build": "esbuild src/plotly-graph-card.ts --outdir=dist --bundle --minify",
1010
"test": "jest",
11-
"test:watch": "jest --watchAll"
11+
"test:watch": "jest --watchAll",
12+
"version": "npm run build && git add ."
1213
},
1314
"author": "",
1415
"license": "ISC",

src/Cache.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ export default class Cache {
9898
const histories: Histories = {};
9999
for (const history of list) {
100100
const name = history[0].entity_id;
101-
this.attributes[name] = history[0].attributes;
101+
this.attributes[name] = {
102+
unit_of_measurement: "",
103+
...history[0].attributes,
104+
};
102105
histories[name] = history.map((entry) => ({
103106
...entry,
104107
last_changed: +new Date(entry.last_changed),

src/plotly-graph-card.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import merge from "lodash-es/merge";
99
import getThemedLayout from "./themed-layout";
1010
import EventEmitter from "events";
1111
import mapValues from "lodash/mapValues";
12-
import uniq from "lodash/mapValues";
1312

1413
console.info(
1514
`%c PLOTLY-GRAPH-CARD %c ${version} `,
@@ -141,7 +140,7 @@ export class PlotlyGraph extends HTMLElement {
141140
const { histories, attributes } = this.cache;
142141

143142
const units = Array.from(
144-
new Set(Object.values(attributes).map((a) => a.unit_of_measurement || ""))
143+
new Set(Object.values(attributes).map((a) => a.unit_of_measurement))
145144
);
146145

147146
this.data = entities.map((trace) => {
@@ -216,6 +215,13 @@ export class PlotlyGraph extends HTMLElement {
216215
getCardSize() {
217216
return 30;
218217
}
218+
static getStubConfig() {
219+
return {
220+
entities: [
221+
{ entity: "sun.sun", hours_to_show: 24, refresh_interval: 10 },
222+
],
223+
};
224+
}
219225
}
220226

221227
customElements.define("plotly-graph", PlotlyGraph);

src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export type History = {
1414
last_changed: Timestamp;
1515
state: string;
1616
attributes: {
17-
friendly_name: string;
18-
unit_of_measurement: string;
17+
friendly_name?: string;
18+
unit_of_measurement?: string;
1919
};
2020
}[];
2121
export type TimestampRange = Timestamp[]; // [Timestamp, Timestamp];

0 commit comments

Comments
 (0)