Skip to content

Commit badcb30

Browse files
committed
Fix broken statistics when set via defaults
1 parent 8bb817a commit badcb30

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

src/plotly-graph-card.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -207,23 +207,8 @@ export class PlotlyGraph extends HTMLElement {
207207

208208
entities: config.entities.map((entityIn, entityIdx) => {
209209
if (typeof entityIn === "string") entityIn = { entity: entityIn };
210-
if ("statistic" in entityIn || "period" in entityIn) {
211-
const validStatistic = ["mean", "min", "max", "sum"].includes(
212-
entityIn.statistic || ""
213-
);
214-
if (!validStatistic) entityIn.statistic = "mean";
215-
const validPeriod = ["5minute", "hour", "day", "month"].includes(
216-
entityIn.period || ""
217-
);
218-
if (!validPeriod) entityIn.period = "hour";
219-
}
220-
const [oldAPI_entity, oldAPI_attribute] = entityIn.entity.split("::");
221-
if (oldAPI_attribute) {
222-
entityIn.entity = oldAPI_entity;
223-
entityIn.attribute = oldAPI_attribute;
224-
}
225210

226-
return merge(
211+
const entityOut = merge(
227212
{
228213
hovertemplate: `<b>%{customdata.name}</b><br><i>%{x}</i><br>%{y}%{customdata.unit_of_measurement}<extra></extra>`,
229214
mode: "lines",
@@ -240,6 +225,22 @@ export class PlotlyGraph extends HTMLElement {
240225
lambda: entityIn.lambda ? window.eval(entityIn.lambda) : undefined,
241226
}
242227
);
228+
if ("statistic" in entityOut || "period" in entityOut) {
229+
const validStatistic = ["mean", "min", "max", "sum"].includes(
230+
entityOut.statistic || ""
231+
);
232+
if (!validStatistic) entityOut.statistic = "mean";
233+
const validPeriod = ["5minute", "hour", "day", "month"].includes(
234+
entityOut.period || ""
235+
);
236+
if (!validPeriod) entityOut.period = "hour";
237+
}
238+
const [oldAPI_entity, oldAPI_attribute] = entityOut.entity.split("::");
239+
if (oldAPI_attribute) {
240+
entityOut.entity = oldAPI_entity;
241+
entityOut.attribute = oldAPI_attribute;
242+
}
243+
return entityOut;
243244
}),
244245
layout: merge(
245246
{

0 commit comments

Comments
 (0)