Skip to content

Commit

Permalink
Create new enforce_value_in_range config option, disable by default
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLastProject committed Jul 29, 2019
1 parent 5e08e05 commit 587bf22
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion bar-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 587bf22

Please sign in to comment.