-
Notifications
You must be signed in to change notification settings - Fork 1
/
number-desk-tile-feature.js
92 lines (81 loc) · 2.33 KB
/
number-desk-tile-feature.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import {
LitElement,
html,
css,
} from "https://unpkg.com/lit-element@2.0.1/lit-element.js?module";
const supportsButtonPressTileFeature = (stateObj) => {
const domain = stateObj.entity_id.split(".")[0];
return domain === "number";
};
class ButtonPressTileFeature extends LitElement {
static get properties() {
return {
hass: undefined,
config: undefined,
stateObj: undefined,
};
}
static getStubConfig() {
return {
type: "custom:number-desk-tile-feature",
sitPosition: 420,
standPosition: 3900,
};
}
setConfig(config) {
if (!config) {
throw new Error("Invalid configuration");
}
this.config = config;
}
_sit(ev) {
ev.stopPropagation();
this.hass.callService("number", "set_value", {
entity_id: this.stateObj.entity_id,
value: this.config.sitPosition,
});
}
_stand(ev) {
ev.stopPropagation();
this.hass.callService("number", "set_value", {
entity_id: this.stateObj.entity_id,
value: this.config.standPosition,
});
}
render() {
if (
!this.config ||
!this.hass ||
!this.stateObj ||
!supportsButtonPressTileFeature(this.stateObj)
) {
return null;
}
return html`
<ha-control-button-group>
<ha-control-button .label=sit @click=${this._sit}>
<ha-icon icon="mdi:arrow-down-bold"></ha-icon> Sit
</ha-control-button>
<ha-control-button .label=stand @click=${this._stand}>
<ha-icon icon="mdi:arrow-up-bold"></ha-icon> Stand
</ha-control-button>
</ha-control-button-group>
`;
}
static get styles() {
return css`
ha-control-button-group {
margin: 0 12px 12px 12px;
--control-button-group-spacing: 12px;
}
`;
}
}
customElements.define("number-desk-tile-feature", ButtonPressTileFeature);
window.customTileFeatures = window.customTileFeatures || [];
window.customTileFeatures.push({
type: "number-desk-tile-feature",
name: "Desk Sit/Stand",
supported: supportsButtonPressTileFeature,
configurable: true,
});