mirror of
https://github.com/kalkih/mini-graph-card.git
synced 2025-12-20 00:35:56 +01:00
feat: Add support of attribute tree when available (#996)
* Add support of attribute tree when available * Update README file Authored-by: Eric Vandecasteele <eric@onlinux.fr>
This commit is contained in:
committed by
GitHub
parent
edc6b9085d
commit
9c1c31eaef
@@ -124,7 +124,7 @@ properties of the Entity object detailed in the following table (as per `sensor.
|
||||
| Name | Type | Default | Description |
|
||||
|------|:----:|:-------:|-------------|
|
||||
| entity ***(required)*** | string | | Entity id of the sensor.
|
||||
| attribute | string | | Retrieves an attribute instead of the state
|
||||
| attribute | string | | Retrieves an attribute or sub-attribute (attr1.attr2...) instead of the state
|
||||
| name | string | | Set a custom display name, defaults to entity's friendly_name.
|
||||
| color | string | | Set a custom color, overrides all other color options including thresholds.
|
||||
| unit | string | | Set a custom unit of measurement, overrides `unit` set in base config.
|
||||
|
||||
@@ -270,12 +270,16 @@ class MiniGraphCard extends LitElement {
|
||||
`;
|
||||
}
|
||||
|
||||
getObjectAttr(obj, path) {
|
||||
return path.split('.').reduce((res, key) => res && res[key], obj);
|
||||
}
|
||||
|
||||
getEntityState(id) {
|
||||
const entityConfig = this.config.entities[id];
|
||||
if (this.config.show.state === 'last') {
|
||||
return this.points[id][this.points[id].length - 1][V];
|
||||
} else if (entityConfig.attribute) {
|
||||
return this.entity[id].attributes[entityConfig.attribute];
|
||||
return this.getObjectAttr(this.entity[id].attributes, entityConfig.attribute);
|
||||
} else {
|
||||
return this.entity[id].state;
|
||||
}
|
||||
@@ -907,7 +911,7 @@ class MiniGraphCard extends LitElement {
|
||||
newStateHistory[0].forEach((item) => {
|
||||
if (this.config.entities[index].attribute) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
item.state = item.attributes[this.config.entities[index].attribute];
|
||||
item.state = this.getObjectAttr(item.attributes, this.config.entities[index].attribute);
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
delete item.attributes;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user