@@ -204,43 +204,42 @@ export class PlotlyGraph extends HTMLElement {
204
204
const newConfig : Config = {
205
205
hours_to_show : config . hours_to_show ?? 1 ,
206
206
refresh_interval : config . refresh_interval ?? 0 ,
207
-
208
207
entities : config . entities . map ( ( entityIn , entityIdx ) => {
209
208
if ( typeof entityIn === "string" ) entityIn = { entity : entityIn } ;
210
209
211
- const entityOut = merge (
210
+ const entity = merge (
212
211
{
213
212
hovertemplate : `<b>%{customdata.name}</b><br><i>%{x}</i><br>%{y}%{customdata.unit_of_measurement}<extra></extra>` ,
214
213
mode : "lines" ,
214
+ show_value : false ,
215
215
line : {
216
216
width : 1 ,
217
217
shape : "hv" ,
218
218
color : colorScheme [ entityIdx % colorScheme . length ] ,
219
219
} ,
220
220
} ,
221
221
config . defaults ?. entity ,
222
- entityIn ,
223
- {
224
- show_value : entityIn . show_value ?? false ,
225
- lambda : entityIn . lambda ? window . eval ( entityIn . lambda ) : undefined ,
226
- }
222
+ entityIn
227
223
) ;
228
- if ( "statistic" in entityOut || "period" in entityOut ) {
224
+ if ( entity . lambda ) {
225
+ entity . lambda = window . eval ( entity . lambda ) ;
226
+ }
227
+ if ( "statistic" in entity || "period" in entity ) {
229
228
const validStatistic = [ "mean" , "min" , "max" , "sum" ] . includes (
230
- entityOut . statistic || ""
229
+ entity . statistic || ""
231
230
) ;
232
- if ( ! validStatistic ) entityOut . statistic = "mean" ;
231
+ if ( ! validStatistic ) entity . statistic = "mean" ;
233
232
const validPeriod = [ "5minute" , "hour" , "day" , "month" ] . includes (
234
- entityOut . period || ""
233
+ entity . period || ""
235
234
) ;
236
- if ( ! validPeriod ) entityOut . period = "hour" ;
235
+ if ( ! validPeriod ) entity . period = "hour" ;
237
236
}
238
- const [ oldAPI_entity , oldAPI_attribute ] = entityOut . entity . split ( "::" ) ;
237
+ const [ oldAPI_entity , oldAPI_attribute ] = entity . entity . split ( "::" ) ;
239
238
if ( oldAPI_attribute ) {
240
- entityOut . entity = oldAPI_entity ;
241
- entityOut . attribute = oldAPI_attribute ;
239
+ entity . entity = oldAPI_entity ;
240
+ entity . attribute = oldAPI_attribute ;
242
241
}
243
- return entityOut ;
242
+ return entity as EntityConfig ;
244
243
} ) ,
245
244
layout : merge (
246
245
{
0 commit comments