@@ -13,14 +13,8 @@ class BarCard extends HTMLElement {
13
13
const cardConfig = Object . assign ( { } , config ) ;
14
14
if ( ! cardConfig . height ) cardConfig . height = "40px" ;
15
15
if ( ! cardConfig . from ) cardConfig . from = "left" ;
16
- if ( cardConfig . from == "left" )
17
- {
18
- cardConfig . from = "right" ;
19
- }
20
- else
21
- {
22
- cardConfig . from = "left" ;
23
- }
16
+ if ( cardConfig . from == "left" ) cardConfig . from = "right" ;
17
+ else cardConfig . from = "left" ;
24
18
if ( ! config . rounding ) config . rounding = "3px" ;
25
19
if ( ! config . width ) config . width = "70%" ;
26
20
if ( ! config . indicator ) config . indicator = true ;
@@ -159,7 +153,7 @@ class BarCard extends HTMLElement {
159
153
for ( ; i <= totalFrames ; ) {
160
154
let brightness = this . _scale ( i / 10 , currentPercent , currentPercent + 25 , 50 , 15 ) ;
161
155
if ( brightness <= 15 ) brightness = 15 ;
162
- let keyframe = { "--bar-charge-percent" : i / 10 + "%" , "--bar-charge-color" : "hsla(" + hue + "," + saturation + "," + brightness + "%,0.5)" } ;
156
+ let keyframe = { "--bar-charge-percent" : i / 10 + "%" , "--bar-percent" : currentPercent + "%" , "--bar- charge-color" : "hsla(" + hue + "," + saturation + "," + brightness + "%,0.5)" } ;
163
157
keyframes . push ( keyframe ) ;
164
158
i ++ ;
165
159
}
@@ -212,10 +206,16 @@ class BarCard extends HTMLElement {
212
206
if ( ! config . animation ) config . animation = 'auto' ;
213
207
if ( ! config . indicator ) config . indicator = true ;
214
208
const root = this . shadowRoot ;
215
- let entityState = hass . states [ config . entity ] . state ;
216
- entityState = Math . min ( entityState , config . max ) ;
217
- entityState = Math . max ( entityState , config . min ) ;
218
- const measurement = hass . states [ config . entity ] . attributes . unit_of_measurement || "" ;
209
+ let entityState ;
210
+ if ( hass . states [ config . entity ] == undefined || hass . states [ config . entity ] . state == "unknown" ) entityState = "N/A" ;
211
+ else {
212
+ entityState = hass . states [ config . entity ] . state ;
213
+ entityState = Math . min ( entityState , config . max ) ;
214
+ entityState = Math . max ( entityState , config . min ) ;
215
+ }
216
+ let measurement
217
+ if ( hass . states [ config . entity ] == undefined || hass . states [ config . entity ] . state == "unknown" ) measurement = "" ;
218
+ else measurement = hass . states [ config . entity ] . attributes . unit_of_measurement || "" ;
219
219
let hue ;
220
220
if ( ! config . severity ) {
221
221
hue = 220 ;
@@ -226,7 +226,6 @@ class BarCard extends HTMLElement {
226
226
else {
227
227
hue = this . _computeSeverity ( entityState , config . severity ) ;
228
228
}
229
- //const gradientHue = scale((100 - this._translatePercent(entityState, config.min, config.max)), 0, 100, 0, 120);
230
229
const color = 'hsl(' + hue + ',' + config . saturation + ',50%)' ;
231
230
const backgroundColor = 'hsla(' + hue + ',' + config . saturation + ',15%,0.5)' ;
232
231
const chargeColor = 'hsla(' + hue + ',' + config . saturation + ',30%,0.5)' ;
@@ -263,10 +262,14 @@ class BarCard extends HTMLElement {
263
262
}
264
263
265
264
if ( config . animation == 'charge' ) {
265
+ let chargeEntityState ;
266
266
if ( ! config . charge_entity ) {
267
- throw new Error ( 'Please define a charge entity' ) ;
267
+ entityState = "define 'charge_entity'" ;
268
+ measurement = "" ;
269
+ root . getElementById ( "value" ) . style . setProperty ( 'color' , '#FF0000' ) ;
270
+ } else {
271
+ chargeEntityState = hass . states [ config . charge_entity ] . state ;
268
272
}
269
- const chargeEntityState = hass . states [ config . charge_entity ] . state ;
270
273
if ( chargeEntityState == "charging" || chargeEntityState == "on" || chargeEntityState == "true" ) {
271
274
root . getElementById ( "indicator" ) . style . setProperty ( 'right' , 0 ) ;
272
275
root . getElementById ( "indicator" ) . textContent = '▲' ;
0 commit comments