Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create new enforce_value_in_range config option, disable by default #16

Merged
merged 1 commit into from
Jul 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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