This repository has been archived by the owner on Jun 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtoggle-lock-entity-row.js
98 lines (93 loc) · 2.39 KB
/
toggle-lock-entity-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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
class ToggleLockEntityRow extends Polymer.Element {
static get template() {
return Polymer.html`
<style>
hui-generic-entity-row {
margin: var(--ha-themed-slider-margin, initial);
}
.flex {
display: flex;
align-items: center;
}
#overlay {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
text-align: right;
z-index: 1;
}
#lock {
margin-top: 8px;
opacity: 1;
margin-right: 7px;
-webkit-animation-duration: 5s;animation-duration 5s;
-webkit-animation-fill-mode: both;animation-full-mode: both;
}
.wrapper {
position: relative;
}
@keyframes fadeOut{
0% {opacity: 1;}
20% {opacity: 0;}
80% {opacity: 0;}
100% {opacity: 1;}
}
.fadeOut {
-webkit-animation-name: fadeOut;animation-name: fadeOut;
}
</style>
<hui-generic-entity-row
config="[[_config]]"
hass="[[_hass]]"
>
<div class="wrapper">
<div class="flex">
<ha-entity-toggle
state-obj="[[stateObj]]"
hass="[[_hass]]"
></ha-entity-toggle>
</div>
<div id="overlay" on-click='clickHandler'>
<iron-icon id="lock" icon="mdi:lock-outline"></iron-icon>
</div>
</div>
</hui-generic-entity-row>
`
}
setConfig(config)
{
this._config = config;
this.users = null;
if(config.users) {
this.users = config.users;
}
}
set hass(hass) {
this._hass = hass;
this.stateObj = this._config.entity in hass.states ? hass.states[this._config.entity] : null;
}
clickHandler(e) {
e.stopPropagation();
if(this.users) {
if(! document.querySelector("home-assistant").hass.user) return;
let user = document.querySelector("home-assistant").hass.user.name;
if(this.users.indexOf(user) < 0) return;
}
this.$.overlay.style.pointerEvents = 'none';
const lock = this.$.lock;
if(lock) {
lock.icon = 'mdi:lock-open-outline';
lock.classList.add('fadeOut');
}
window.setTimeout(() => {
this.$.overlay.style.pointerEvents = '';
if(lock) {
lock.classList.remove('fadeOut');
lock.icon = 'mdi:lock-outline';
}
}, 5000);
}
}
customElements.define('toggle-lock-entity-row', ToggleLockEntityRow);