forked from custom-cards/state-element
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate-element.js
36 lines (35 loc) · 933 Bytes
/
state-element.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class StateElement extends HTMLElement {
set hass(hass) {
const entityId = this.config.entity;
const prefix_string = this.config.prefix
const show_empty = this.config.show_empty
const state = hass.states[entityId].state;
const card = document.createElement('state-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;
}
}
}
setConfig(config) {
if (!config.entity) {
throw new Error('You need to define an entity');
}
if (!config.show_empty) {
config.show_empty = false;
}
this.config = config;
}
getCardSize() {
return 1;
}
}
customElements.define('state-element', StateElement);