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

Commit

Permalink
Add support for configuring a suffix string + simplify logic (#5)
Browse files Browse the repository at this point in the history
* Add support for configuring a suffix string + simplify logic

* Document suffix config

* Update VERSION
  • Loading branch information
nervetattoo authored and ludeeus committed Sep 29, 2018
1 parent dfc5dc2 commit 3715bbc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 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: "
| suffix | string | **Optional** | A string you want to show after the attribute, ex. "My suffix 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.4
0.1.0
19 changes: 5 additions & 14 deletions state-attribute-element.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
class StateAttributeElement extends HTMLElement {
set hass(hass) {
const entityId = this.config.entity;
const prefix_string = this.config.prefix
const prefix_string = this.config.prefix || ''
const suffix_string = this.config.suffix || ''
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 (state.length != 0) {
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;
}
if (state.length != 0 || show_empty === true) {
this.innerHTML = `${prefix_string}${state}${suffix_string}`
}
}
setConfig(config) {
Expand All @@ -37,4 +28,4 @@ class StateAttributeElement extends HTMLElement {
return 1;
}
}
customElements.define('state-attribute-element', StateAttributeElement);
customElements.define('state-attribute-element', StateAttributeElement);

0 comments on commit 3715bbc

Please sign in to comment.