Skip to content

Commit

Permalink
Fix state icon for color_type: card and equal operators (#82)
Browse files Browse the repository at this point in the history
* Fix state icon for color_type: card and equal operators

* Fix missing icon when no icon in default config and state used
  • Loading branch information
RomRider authored and iantrich committed Apr 14, 2019
1 parent 59a1ccf commit 416fb89
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,16 +285,16 @@ The definition order matters, the first item to match will be the one selected.

Available operators:

| Operator | `value` example | Description |
| :-------: | --------------- | ------------------------------------------------ |
| `<` | `5` | State is inferior to `value` |
| `<=` | `4` | State is inferior or equal to `value` |
| `==` | `42` | State is equal (`===` javascript) to `value` |
| `>=` | `32` | State is superior or equal to `value` |
| `>` | `12` | State is superior to `value` |
| `!=` | `normal` | State is not equal (`!==` javascript) to `value` |
| `regex` | `'^norm.*$'` | `value` regex applied to State does match |
| `default` | N/A | If nothing matches, this is used |
| Operator | `value` example | Description |
| :-------: | --------------- | ----------------------------------------------- |
| `<` | `5` | State is inferior to `value` |
| `<=` | `4` | State is inferior or equal to `value` |
| `==` | `42` | State is equal (`==` javascript) to `value` |
| `>=` | `32` | State is superior or equal to `value` |
| `>` | `12` | State is superior to `value` |
| `!=` | `normal` | State is not equal (`!=` javascript) to `value` |
| `regex` | `'^norm.*$'` | `value` regex applied to State does match |
| `default` | N/A | If nothing matches, this is used |


## Credits
Expand Down
9 changes: 5 additions & 4 deletions button-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
if (elt.operator) {
switch (elt.operator) {
case '==':
return (state.state === elt.value)
return (state.state == elt.value)
case '<=':
return (state.state <= elt.value)
case '<':
Expand All @@ -104,7 +104,7 @@
case '>':
return (state.state > elt.value)
case '!=':
return (state.state !== elt.value)
return (state.state != elt.value)
case 'regex':
return (state.state.match(elt.value))
case 'default':
Expand Down Expand Up @@ -184,11 +184,12 @@
cardColoredHtml(state, config) {
const color = this.buildCssColorAttribute(state, config);
const fontColor = this.getFontColorBasedOnBackgroundColor(color);
const icon = this.buildIcon(state, config);
return html`
<ha-card style="color: ${fontColor};" @tap="${ev => this._toggle(state, config)}">
<button-card-button style="background-color: ${color}; ${config.card_style}">
<div style="${config.card_style}">
${config.icon ? html`<ha-icon style="width: ${config.size}; height: ${config.size};" icon="${config.icon}"></ha-icon>` : ''}
${config.icon || icon ? html`<ha-icon style="width: ${config.size}; height: ${config.size};" icon="${icon}"></ha-icon>` : ''}
${config.name ? html`<span>${config.name}</span>` : ''}
${config.show_state ? html`<span>${state.state} ${state.attributes.unit_of_measurement ? state.attributes.unit_of_measurement : ''}</span>` : ''}
</div>
Expand All @@ -204,7 +205,7 @@
<ha-card @tap="${ev => this._toggle(state, config)}">
<button-card-button style="${config.card_style}">
<div style="${config.card_style}">
${config.icon ? html`<ha-icon style="color: ${color}; width: ${config.size}; height: ${config.size};" icon="${icon}"></ha-icon>` : ''}
${config.icon || icon ? html`<ha-icon style="color: ${color}; width: ${config.size}; height: ${config.size};" icon="${icon}"></ha-icon>` : ''}
${config.name ? html`<div>${config.name}</div>` : ''}
${config.show_state ? html`<div>${state.state} ${state.attributes.unit_of_measurement ? state.attributes.unit_of_measurement : ''}</div>` : ''}
</div>
Expand Down

0 comments on commit 416fb89

Please sign in to comment.