-
Notifications
You must be signed in to change notification settings - Fork 14
/
card.js
33 lines (28 loc) · 887 Bytes
/
card.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
class HelloWorldCard extends HTMLElement {
config;
content;
// required
setConfig(config) {
this.config = config;
}
set hass(hass) {
const entityId = this.config.entity;
const state = hass.states[entityId];
const stateStr = state ? state.state : 'unavailable';
// done once
if (!this.content) {
// user makes sense here as every login gets it's own instance
this.innerHTML = `
<ha-card header="Hello ${hass.user.name}!">
<div class="card-content"></div>
</ha-card>
`;
this.content = this.querySelector('div');
}
// done repeatedly
this.content.innerHTML = `
<p>The ${entityId} is ${stateStr}.</p>
`;
}
}
customElements.define('hello-world-card', HelloWorldCard);