-
Notifications
You must be signed in to change notification settings - Fork 0
/
only-lock-lock-row.js
77 lines (68 loc) · 1.76 KB
/
only-lock-lock-row.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
window.customCards = window.customCards || [];
window.customCards.push({
type: 'only-lock-lock-row',
name: 'Only Lock Lock row',
description: 'A plugin to only lock a Lock.',
preview: false,
});
const LitElement = customElements.get('ha-panel-lovelace') ?
Object.getPrototypeOf(customElements.get('ha-panel-lovelace')) :
Object.getPrototypeOf(customElements.get('hc-lovelace'));
const html = LitElement.prototype.html;
/**
* Only Lock Lock custom entity
*/
export class OnlyLockLockRow extends LitElement {
constructor() {
super();
}
render() {
return html`
<style include="iron-flex iron-flex-alignment"></style>
<style>
mwc-button {
top: 3px;
height: 37px;
margin-right: -0.57em;
}
</style>
<hui-generic-entity-row .hass="${this.hass}" .config="${this._config}">
<div class="horizontal justified layout">
<state-info hass="[[hass]]" state-obj="[[stateObj]]"></state-info>
<button @click=${this.callLockService}>Lock</button>
</div>
</hui-generic-entity-row>
`;
}
static get properties() {
return {
hass: Object,
stateObj: {
type: Object,
observer: '_stateObjChanged',
},
};
}
setConfig(config) {
this._config = {
tap_action: {
action: 'none',
},
...config,
};
}
displayName() {
return this._config.name || this.stateObj.attributes.friendly_name;
}
_stateObjChanged(newVal) {
this.setProperties({
_stateObj: stateObj,
});
}
callLockService() {
const data = {
entity_id: this._config.entity,
};
this.hass.callService('lock', 'lock', data);
}
}