This repository has been archived by the owner on May 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
ext-weblink.js
76 lines (72 loc) · 1.95 KB
/
ext-weblink.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
class ExtWebLink extends HTMLElement {
set hass(hass) {
if (!this.config.icon) {
this.config.icon = "mdi:home-assistant";
}
if (!this.config.entity) {
var state = "";
} else {
if (hass.states[this.config.entity].attributes.unit_of_measurement) {
var state = hass.states[this.config.entity].state+' '+hass.states[this.config.entity].attributes.unit_of_measurement;
} else {
var state = hass.states[this.config.entity].state
}
}
if (this.config.name) {
var name = this.config.name;
} else {
var name = hass.states[this.config.entity].attributes.friendly_name;
}
if (!this.config.url) {
this.config.url = "#";
}
this.innerHTML =`
<style>
a {
align-items: center;
color: var(--primary-color);
text-decoration-line: none;
}
ha-icon {
padding: 8px;
color: var(--paper-item-icon-color);
}
ha-icon .innline {
padding: 0px;
color: var(--paper-item-icon-color);
}
div {
flex: 1;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
div .state {
text-align: right;
padding: 10px 0px 10px 0px;
}
div .name {
text-align: left;
overflow: visible;
padding: 10px 12px 10px 16px;
}
div .main {
display: flex;
}
</style>
<div class="main">
<ha-icon icon="${this.config.icon}"></ha-icon>
<div class="name">${name}</div>
<a href="${this.config.url}" target="_blank"><ha-icon icon="mdi:open-in-new" class="innline"></ha-icon></a>
<div class="state">${state}</div>
</div>
`;
}
setConfig(config) {
this.config = config;
}
getCardSize() {
return 1;
}
}
customElements.define('ext-weblink', ExtWebLink);