diff --git a/README.md b/README.md index 43e359d..f0c8d7d 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ Bar Card is a customizable animated card for the Home Assistant Lovelace front-e | columns | number | none | Number of columns when using entities list. | attribute | string | none | Attribute to be displayed. | show_value | boolean | true | Hides value display when set to `false`. +| enforce_value_in_range | boolean | false | Ensure the value is always within the minimum and maximum when set to `true`. | show_minmax | boolean | false | Hides the minimum and maximum value when set to `false`. | unit_of_measurement | string | none | Unit of measurement to be displayed. | color | string | var(--primary-color) | Color of the bar, can be any valid CSS color value or variable. diff --git a/bar-card.js b/bar-card.js index cbe04e1..4b3a389 100644 --- a/bar-card.js +++ b/bar-card.js @@ -24,6 +24,7 @@ class BarCard extends HTMLElement { if (!config.color) config.color = 'var(--primary-color)' if (!config.tap_action) config.tap_action = 'info' if (!config.show_value) config.show_value = true + if (!config.enforce_value_in_range) config.enforce_value_in_range = false if (!config.show_minmax) config.show_minmax = false if (!config.title) config.title = false if (!config.severity) config.severity = false @@ -999,7 +1000,7 @@ class BarCard extends HTMLElement { } else { entityState = entityObject.state } - if (!isNaN(entityState)) { + if (config.enforce_value_in_range && !isNaN(entityState)) { entityState = Math.min(entityState, configMax) entityState = Math.max(entityState, configMin) }