Skip to content

Commit

Permalink
Merge pull request #103 from amaximus/master
Browse files Browse the repository at this point in the history
Add support for displaying complementary value
  • Loading branch information
Gluwc authored Aug 12, 2020
2 parents a7a0760 + 49d1d26 commit 63accb1
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
| attribute | string | none | Displays a specific attribute instead of state value.
| color | string | var(--custom-bar-card-color, var(--primary-color)) | Color of the bar.
| columns | number | none | Defines the amount of bars to be displayed on a single row when multiple entities are defined.
| complementary | boolean | false | Displays complementary value (max - state_value) instead state value.
| decimal | number | none | The amount of decimals to be displayed for the value.
| direction | string | right | Direction of the bar. `right`, `up`
| entities | array | none | A list of entities. Accepts individual config options per defined entity.
Expand Down
3 changes: 2 additions & 1 deletion info.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
| attribute | string | none | Displays a specific attribute instead of state value.
| color | string | var(--custom-bar-card-color, var(--primary-color)) | Color of the bar.
| columns | number | none | Defines the amount of bars to be displayed on a single row when multiple entities are defined.
| complementary | boolean | false | Displays complementary value (max - state_value) instead state value.
| decimal | number | none | The amount of decimals to be displayed for the value.
| direction | string | right | Direction of the bar. `right`, `up`
| entities | array | none | A list of entities. Accepts individual config options per defined entity.
Expand Down Expand Up @@ -97,4 +98,4 @@ See [example](#200-default-layout-requires-card-mod). (**requires** [card-mod](h
| bar-card-animationbar | Animated part of the bar.
| bar-card-targetbar | Target bar element.
| bar-card-targetmarker | Target marker element.
| bar-card-indicator | Indicator element.
| bar-card-indicator | Indicator element.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bar-card",
"version": "3.1.7",
"version": "3.2.0",
"description": "Lovelace bar-card",
"keywords": [
"home-assistant",
Expand Down
4 changes: 2 additions & 2 deletions src/bar-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ export class BarCard extends LitElement {
case 'outside':
valueOutside = html`
<bar-card-value class="${config.direction == 'up' ? 'value-direction-up' : 'value-direction-right'}"
>${entityState} ${unitOfMeasurement}</bar-card-value
>${config.complementary ? config.max - entityState : entityState} ${unitOfMeasurement}</bar-card-value
>
`;
break;
Expand All @@ -300,7 +300,7 @@ export class BarCard extends LitElement {
: config.direction == 'up'
? 'value-direction-up'
: 'value-direction-right'}"
>${entityState} ${unitOfMeasurement}</bar-card-value
>${config.complementary ? config.max - entityState : entityState} ${unitOfMeasurement}</bar-card-value
>
`;
break;
Expand Down
21 changes: 21 additions & 0 deletions src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,27 @@ export class BarCardEditor extends LitElement implements LovelaceCardEditor {
>Limit Value</ha-switch
>
`}
${config.complementary
? html`
<ha-switch
checked
.configAttribute=${'complementary'}
.configObject=${config}
.value=${!config.complementary}
@change=${this._valueChanged}
>Complementary</ha-switch
>
`
: html`
<ha-switch
unchecked
.configObject=${config}
.configAttribute=${'complementary'}
.value=${!config.complementary}
@change=${this._valueChanged}
>Complementary</ha-switch
>
`}
<paper-input
class="value-number"
label="Decimal"
Expand Down
6 changes: 4 additions & 2 deletions src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,9 @@

// Update value.
if (config.positions.value !== 'off')
root.getElementById('value_' + id).textContent = `${entityState} ${measurement}`;
if (config.complementary)
root.getElementById('value_' + id).textContent = `${configMax - entityState} ${measurement}`;
else root.getElementById('value_' + id).textContent = `${entityState} ${measurement}`;

// Update bar.
root.getElementById('bar_' + id).style.setProperty('--bar-color', barColor);
Expand Down Expand Up @@ -922,4 +924,4 @@
);
}
this._entityState[id] = entityState;
}
}
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface BarCardConfig {
attribute: any;
color: string;
columns: number;
complementary: boolean;
decimal: any;
direction: string;
double_tap_action?: ActionConfig;
Expand Down

0 comments on commit 63accb1

Please sign in to comment.