Skip to content

Commit

Permalink
feat: add ability to combine attribute and entity_id in stats
Browse files Browse the repository at this point in the history
  • Loading branch information
denysdovhan committed Jun 9, 2023
1 parent 92a78b2 commit e9d8667
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Here is what every option means:

### `stats` object

You can use any attribute of vacuum or even any entity by `entity_id` to display by stats section:
You can use any attribute of vacuum or even any entity by `entity_id` to display by stats section. You can also combine `attribute` with `entity_id` to extract an attribute value of specific entity:

| Name | Type | Default | Description |
| ---------------- | :------: | -------- | ---------------------------------------------------------------------------------------------------- |
Expand Down
14 changes: 11 additions & 3 deletions src/vacuum-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,17 @@ export class VacuumCard extends LitElement {
return nothing;
}

const state = entity_id
? this.hass.states[entity_id].state
: get(this.entity.attributes, attribute ?? '');
let state = '';

if (entity_id && attribute) {
state = get(this.hass.states[entity_id].attributes, attribute);
} else if (attribute) {
state = get(this.entity.attributes, attribute);
} else if (entity_id) {
state = this.hass.states[entity_id].state;
} else {
return nothing;
}

const value = html`
<ha-template
Expand Down

0 comments on commit e9d8667

Please sign in to comment.