Skip to content
This repository has been archived by the owner on May 28, 2022. It is now read-only.

Commit

Permalink
Added show_empty option (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus authored Jul 25, 2018
1 parent 63d1143 commit 23d1155
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This element is **not** all that useful as a card (it can be used for that to),
| entity | string | **Required** | The entity_id of the entity you want to show.
| attribute | string | **Required** | The attribute of the entity you want to show.
| prefix | string | **Optional** | A string you want to show in front of the attribute, ex. "My prefix string: "
| show_empty | boolean | **Optional** | Give you the possibility to show `unavailable` if the state is empty, default `false`

## Installation

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.2
0.0.3
20 changes: 16 additions & 4 deletions state-attribute-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@ class StateAttributeElement extends HTMLElement {
set hass(hass) {
const entityId = this.config.entity;
const prefix_string = this.config.prefix
const show_empty = this.config.show_empty
const attr = this.config.attribute;
const state = hass.states[entityId].attributes[attr];
const card = document.createElement('state-attribute-element');
if (prefix_string) {
this.innerHTML = prefix_string + state;
} else {
this.innerHTML = state;
if (state != null) {
if (prefix_string) {
this.innerHTML = prefix_string + state;
} else {
this.innerHTML = state;
}
} else if (show_empty == true) {
if (prefix_string) {
this.innerHTML = prefix_string + state;
} else {
this.innerHTML = state;
}
}
}
setConfig(config) {
Expand All @@ -18,6 +27,9 @@ class StateAttributeElement extends HTMLElement {
if (!config.attribute) {
throw new Error('You need to define an attribute');
}
if (!config.show_empty) {
config.show_empty = false;
}
this.config = config;
}

Expand Down

0 comments on commit 23d1155

Please sign in to comment.