Skip to content

Commit

Permalink
Config to specify attribute as max and config to show max value (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
iantrich authored and jeradM committed Aug 8, 2018
1 parent 016980c commit 9b3b78c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ Custom component for lovelace which can be used as a card or an element on a pic
| color_stops | object | Sensor value to color mapping (see below) | none
| gradient | boolean | Whether to smoothly transition between color stops | `false`
| units | string | Custom units of measurement | none
| attribute | string | Attribute element of an entity to use instead of its state | none
| attribute | string | Attribute element of entity to use instead of its state | none
| attribute_max | string | Use attribute element of entity as max | none
| show_max | boolean | Display the max value | `false`

### Color stops
A mapping from `value` to `color`. If `gradient` is set to true, mid-stop colors will be
Expand Down Expand Up @@ -70,6 +72,8 @@ Add a custom card or custom element in your `ui-lovelace.yaml` using `type: cust
gradient: true
units: ' '
attribute: 'ambient'
attribute_max: 'feels_like'
show_max: true
font_style:
color: red
font-size: 1.5em
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.0
1.2.0
8 changes: 6 additions & 2 deletions circle-sensor-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ class CircleSensorCard extends LitElement {
${config.attribute ? state.attributes[config.attribute] : state.state}
</span>
<span class="unit">
${config.units ? config.units : state.attributes.unit_of_measurement}
${config.show_max
? html`&nbsp/ ${config.attribute_max ? state.attributes[config.attribute_max] : config.max}`
: (config.units ? config.units : state.attributes.unit_of_measurement)}
</span>
</span>
</span>
Expand Down Expand Up @@ -147,7 +149,9 @@ class CircleSensorCard extends LitElement {
: this.state.state;
const r = 200 * .45;
const min = this.config.min || 0;
const max = this.config.max || 100;
const max = this.config.attribute_max
? this.state.attributes[this.config.attribute_max]
: (this.config.max || 100);
const val = this._calculateValueBetween(min, max, state);
const score = val * 2 * Math.PI * r;
const total = 10 * r;
Expand Down

0 comments on commit 9b3b78c

Please sign in to comment.