Skip to content

Commit

Permalink
Merge pull request #24 from SNoof85/min-max-attr
Browse files Browse the repository at this point in the history
Min max entities attribute
  • Loading branch information
SNoof85 authored Feb 15, 2021
2 parents adc47b6 + 9119ee7 commit ae4b906
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ Add it as a custom card to your lovelace : `'custom:tempometer-gauge-card'`.
### Card options
| **Option** | **Type** | **Description** |
|-|:-:|-|
| `entity` ***(required)*** | string | The entity to track. |
| `attribute`| string | The entity attribute to track. |
| `entity` ***(required)*** | string | The entity to track. Can be followed by an attribute to track `entity.attribute)`|
| `min` ***(required)*** | number | The gauge's minimum value |
| `max` ***(required)*** | number | The gauge's maximum value |
| `entity_min` | string | The entity that define the minimum pressure/temperature reached (you have to create this entity, the card will not compute it !) |
| `entity_max` | string | The entity that define the maximum pressure/temerature reached (you have to create this entity, the card will not compute it !) |
| `entity_min` | string | The entity that define the minimum reached. Can be followed by an attribute to track `entity.attribute)` (you have to create this entity, the card will not compute it !) |
| `entity_max` | string | The entity that define the maximum reached. Can be followed by an attribute to track `entity.attribute)` (you have to create this entity, the card will not compute it !) |
| `title` | string | Card title to show. |
| `style` | string | Set this to `thermometer`, `humidity` or `custom` to change icons. (Default will be barometer theme, custom will need icon1, icon2, icon3 !) |
| `measurement` | string | Custom unit of measurement |
Expand Down
16 changes: 12 additions & 4 deletions tempometer-gauge-card.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
console.info(`%c TEMPOMETER-CARD \n%c v1.1 `, 'color: orange; font-weight: bold; background: black', 'color: white; font-weight: bold; background: dimgray');
console.info(`%c TEMPOMETER-CARD \n%c v1.2 `, 'color: orange; font-weight: bold; background: black', 'color: white; font-weight: bold; background: dimgray');
class TempometerGaugeCard extends HTMLElement {
constructor() {
super();
Expand Down Expand Up @@ -29,7 +29,15 @@ class TempometerGaugeCard extends HTMLElement {
cardConfig.entity = entityParts.entity;
if (entityParts.attribute) cardConfig.attribute = entityParts.attribute;

let card_style = cardConfig.style;
const entityMinParts = this._splitEntityAndAttribute(cardConfig.entity_min);
cardConfig.entity_min = entityMinParts.entity;
if (entityMinParts.attribute) cardConfig.minAttribute = entityMinParts.attribute;

const entityMaxParts = this._splitEntityAndAttribute(cardConfig.entity_max);
cardConfig.entity_max = entityMaxParts.entity;
if (entityMaxParts.attribute) cardConfig.maxAttribute = entityMaxParts.attribute;

let card_style = cardConfig.style;
const card = document.createElement('ha-card');
const content = document.createElement('div');
const style = document.createElement('style');
Expand Down Expand Up @@ -332,12 +340,12 @@ class TempometerGaugeCard extends HTMLElement {
var maxEntityState = null;
var minEntityState = null;
if (config.entity_max !== undefined) {
maxEntityState = this._getEntityStateValue(hass.states[config.entity_max], config.attribute);
maxEntityState = this._getEntityStateValue(hass.states[config.entity_max], config.maxAttribute);
} else {
root.getElementById("recentMax").style.display = 'none';
}
if (config.entity_min !== undefined) {
minEntityState = this._getEntityStateValue(hass.states[config.entity_min], config.attribute);
minEntityState = this._getEntityStateValue(hass.states[config.entity_min], config.minAttribute);
} else {
root.getElementById("recentMin").style.display = 'none';
}
Expand Down

0 comments on commit ae4b906

Please sign in to comment.