Skip to content

Commit af5d398

Browse files
committed
1.4.0
* Added `limit_value` config option. * Added `unavailable` as possible state to display as `N/A`.
1 parent 587bf22 commit af5d398

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Bar Card is a customizable animated card for the Home Assistant Lovelace front-e
2222
| columns | number | none | Number of columns when using entities list.
2323
| attribute | string | none | Attribute to be displayed.
2424
| show_value | boolean | true | Hides value display when set to `false`.
25-
| enforce_value_in_range | boolean | false | Ensure the value is always within the minimum and maximum when set to `true`.
25+
| limit_value | boolean | false | Ensure the value is always within the minimum and maximum when set to `true`.
2626
| show_minmax | boolean | false | Hides the minimum and maximum value when set to `false`.
2727
| unit_of_measurement | string | none | Unit of measurement to be displayed.
2828
| color | string | var(--primary-color) | Color of the bar, can be any valid CSS color value or variable.

bar-card.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class BarCard extends HTMLElement {
2424
if (!config.color) config.color = 'var(--primary-color)'
2525
if (!config.tap_action) config.tap_action = 'info'
2626
if (!config.show_value) config.show_value = true
27-
if (!config.enforce_value_in_range) config.enforce_value_in_range = false
27+
if (!config.limit_value) config.limit_value = false
2828
if (!config.show_minmax) config.show_minmax = false
2929
if (!config.title) config.title = false
3030
if (!config.severity) config.severity = false
@@ -992,17 +992,17 @@ class BarCard extends HTMLElement {
992992

993993
// Check for unknown state
994994
let entityState
995-
if (entityObject == undefined || entityObject.state == 'unknown') {
995+
if (entityObject == undefined || entityObject.state == 'unknown' || entityObject.state == 'unavailable') {
996996
entityState = 'N/A'
997997
} else {
998-
if (config.attribute != false) {
998+
if (config.attribute !== false) {
999999
entityState = entityObject.attributes[config.attribute]
10001000
} else {
10011001
entityState = entityObject.state
10021002
}
1003-
if (config.enforce_value_in_range && !isNaN(entityState)) {
1004-
entityState = Math.min(entityState, configMax)
1005-
entityState = Math.max(entityState, configMin)
1003+
if (config.limit_value && !isNaN(entityState)) {
1004+
entityState = Math.min(entityState, configMax)
1005+
entityState = Math.max(entityState, configMin)
10061006
}
10071007
}
10081008

0 commit comments

Comments
 (0)