Skip to content

Commit bea5d18

Browse files
committed
1.5.4
* Fixed NaN display.
1 parent 3847c56 commit bea5d18

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

bar-card.js

+16-9
Original file line numberDiff line numberDiff line change
@@ -762,8 +762,13 @@ class BarCard extends HTMLElement {
762762
const maxValue = this._valueEntityCheck(this._maxCheck(entity, hass, index), hass)
763763
const barElement = this.shadowRoot.getElementById('bar_'+id)
764764

765-
barElement.style.setProperty('--bar-percent', `${this._translatePercent(entityState, minValue, maxValue, index, entity)}%`)
766-
barElement.style.setProperty('--bar-charge-percent', `${this._translatePercent(entityState, minValue, maxValue, index, entity)}%`)
765+
if (!isNaN(entityState)) {
766+
barElement.style.setProperty('--bar-percent', `${this._translatePercent(entityState, minValue, maxValue, index, entity)}%`)
767+
barElement.style.setProperty('--bar-charge-percent', `${this._translatePercent(entityState, minValue, maxValue, index, entity)}%`)
768+
} else {
769+
barElement.style.setProperty('--bar-percent', `100%`)
770+
barElement.style.setProperty('--bar-charge-percent', `100%`)
771+
}
767772
}
768773

769774
// Create animation
@@ -1052,14 +1057,16 @@ class BarCard extends HTMLElement {
10521057
if (entityState !== this._entityState[id]) {
10531058
const barColor = this._calculateBarColor(config, entityState, hass)
10541059

1055-
if (config.visibility !== false) {
1056-
if (entityState == 'N/A' || config.visibility == true) {
1057-
root.getElementById('card_'+id).style.setProperty('--card-display', 'visible')
1058-
} else {
1059-
if (eval(entityState + " " + config.visibility)) {
1060+
if (!isNaN(entityState)) {
1061+
if (config.visibility !== false) {
1062+
if (entityState == 'N/A' || config.visibility == true) {
10601063
root.getElementById('card_'+id).style.setProperty('--card-display', 'visible')
10611064
} else {
1062-
root.getElementById('card_'+id).style.setProperty('--card-display', 'none')
1065+
if (eval(entityState + " " + config.visibility)) {
1066+
root.getElementById('card_'+id).style.setProperty('--card-display', 'visible')
1067+
} else {
1068+
root.getElementById('card_'+id).style.setProperty('--card-display', 'none')
1069+
}
10631070
}
10641071
}
10651072
}
@@ -1190,7 +1197,7 @@ class BarCard extends HTMLElement {
11901197
customElements.define('bar-card', BarCard)
11911198

11921199
console.info(
1193-
`%cBAR-CARD\n%cVersion: 1.5.2`,
1200+
`%cBAR-CARD\n%cVersion: 1.5.4`,
11941201
"color: green; font-weight: bold;",
11951202
""
11961203
);

0 commit comments

Comments
 (0)