-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhue-callionica-four-part-day.html
265 lines (237 loc) · 9.41 KB
/
hue-callionica-four-part-day.html
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>4-Part Day</title>
<link rel="stylesheet" href="hue-callionica.css">
<style>
.limit {
color: lightgray;
}
.numeric {
text-align: right;
}
select {
border-style: solid;
border-width: 0.1rem;
border-color: gray;
padding: 0.2rem;
}
thead {
font-weight: bold;
}
td:first-of-type {
padding: 0;
}
body[loading] select {
color: rgba(0, 0, 0, 0);
}
h4 {
color: darkgray;
}
a {
background: none;
text-decoration: underline;
}
#current-period-delete {
background: none;
visibility: hidden;
}
body[data-manual] #current-period-delete {
visibility: visible;
}
</style>
<script type="module">
import { FourPartDay } from "./hue-callionica-ui.js";
import { loadCurrentBridge, loadConnection } from "./hue-callionica-connect.js";
import { getAll } from "./hue-callionica.js";
let bridge;
let connection;
function populateTimeSelector(e, s) {
e.innerHTML = "";
for (let h = 0; h < 24; ++h) {
for (let m = 0; m < 60; m += 15) {
const t = `${h.toString().padStart(2, "0")}:${m.toString().padStart(2, "0")}`;
const value = "T" + t + ":00";
const o = document.createElement("option");
if (value === s) {
o.selected = true;
}
o.value = value;
o.innerText = t;
e.appendChild(o);
}
}
}
function getFourPartDayRulesFromUI() {
const o = {};
for (const id of FourPartDay.rules) {
const s = `#${id}`;
const e = document.querySelector(s);
o[id] = e.value;
}
return o;
}
async function refreshCurrent() {
const data = await getAll(connection);
const current = document.querySelector("#current-period");
const part = FourPartDay.getPart(data);
current.value = part.name;
if (part.kind === "manual") {
document.body.dataset.manual = true;
} else {
delete document.body.dataset.manual;
}
}
function onRemoveManual() {
FourPartDay.removeManual();
refreshCurrent();
}
function onRuleChange() {
FourPartDay.setRules(getFourPartDayRulesFromUI());
refreshCurrent();
}
function onCurrentChange() {
const current = document.querySelector("#current-period");
const name = current.value;
FourPartDay.setManual({ name, start: new Date() });
document.body.dataset.manual = true;
}
async function main() {
bridge = loadCurrentBridge();
connection = await loadConnection("Callionica", bridge);
const data = await getAll(connection);
const fourPartDayRules = FourPartDay.getRules();
for (const id of FourPartDay.parts) {
const s = `#${id}`;
const e = document.querySelector(s);
populateTimeSelector(e, fourPartDayRules[id]);
e.onchange = onRuleChange;
}
for (const id of FourPartDay.adjustments) {
const s = `#${id}`;
const e = document.querySelector(s);
const o = [...e.querySelectorAll("option")].find(o => o.value === fourPartDayRules[id]);
if (o !== undefined) {
o.selected = true;
}
e.onchange = onRuleChange;
}
const current = document.querySelector("#current-period");
const part = FourPartDay.getPart(data);
current.value = part.name;
if (part.kind === "manual") {
document.body.dataset.manual = true;
} else {
delete document.body.dataset.manual;
}
current.onchange = onCurrentChange;
const clear = document.querySelector("#current-period-delete");
clear.onclick = onRemoveManual;
document.body.removeAttribute("loading");
window.addEventListener('storage', ()=>{}); // TODO
}
async function _main() {
try {
await main();
delete document.body.dataset.showConnection;
// setTimeout(()=> _main(), 60*1000);
} catch (error) {
document.body.dataset.showConnection = true;
const e = document.querySelector("#connection");
if ((bridge === undefined) || (connection === undefined)) {
e.innerHTML = `<a href="hue-callionica-connect.html">Connect to your Hue bridge</a>`;
} else {
e.innerHTML = `<a href="https://${connection.bridge.ip}/api/unauthenticated/config">Refresh your Hue bridge connection</a>`;
}
setTimeout(()=> _main(), 3*1000);
}
}
_main().then(x => console.log("main"));
</script>
</head>
<body loading>
<h1>4-Part Day</h1>
<!--<p>Here you can edit the rules for the four parts of the day.</p>-->
<hr/>
<div id="connection"></div>
<div id="four-part-day">
<h2>Personal Start Times</h2>
<table>
<tr><td>Morning</td><td><select id="morning"><option value="T07:00:00" selected>07:00</option></select></td></tr>
<tr><td>Day</td><td><select id="day"><option value="T08:30:00" selected>08:30</option></select></select></td></tr>
<tr><td>Evening</td><td><select id="evening"><option value="T19:30:00" selected>19:30</option></select></select></td></tr>
<tr><td>Night</td><td><select id="night"><option value="T23:00:00" selected>23:00</option></select></select></td></tr>
</table>
<h2>Daylight Adjustments</h3>
<table>
<thead>
<tr>
<td>Time</td>
<td>Daylight</td>
<td>Result</td>
</tr>
</thead>
<tbody>
<tr>
<td>Morning</td>
<td>Dark</td>
<td><select id="morning-dark">
<option value="night">Night</option>
<option value="morning" selected>Morning</option>
</select></td>
</tr>
<tr>
<td>Day</td>
<td>Dark</td>
<td><select id="day-dark">
<option value="day" selected>Day</option>
<option value="evening">Evening</option>
</select></td>
</tr>
<tr>
<td>Evening</td>
<td>Light</td>
<td><select id="evening-light">
<option value="day">Day</option>
<option value="evening" selected>Evening</option>
</select></td>
</tr>
<tr>
<td>Night</td>
<td>Light</td>
<td><select id="night-light">
<option value="night" selected>Night</option>
<option value="morning">Morning</option>
</select></td>
</tr>
</tbody>
</table>
<h2>Manual Control</h3>
<table>
<tr><td>Current</td><td><select id="current-period">
<option value="morning">Morning</option>
<option value="day" selected>Day</option>
<option value="evening">Evening</option>
<option value="night">Night</option>
</select><button id="current-period-delete" title="Remove manual override">ⓧ</button></td></tr>
</table>
</div>
<hr/>
<table>
<tr><td><h4>Related</h4></td><td></td></tr>
<tr><td><a href="hue-callionica-daylight.html">Time › Daylight</a></td><td></td></tr>
<tr><td><a href="hue-callionica-four-part-day-groups.html">Rooms & Zones</a></td><td></td></tr>
</table>
<hr/>
<p>
Name your scenes "Morning", "Day", "Evening", or "Night" and the Rooms & Zones control panel will use those scenes when you turn on the lights. It will use a fallback
scene if a particular period doesn't have a scene with that name. If there's no appropriate scene, the room or zone will be turned on with its current settings.
</p>
<p>
If the bridge has been configured with your location so that the <a href="hue-callionica-daylight.html">daylight sensor</a> can calculate sunrise and sunset times to determine whether it is currently light or dark, we can use that information to adjust the period if you choose to use Daylight Adjustments.
</p>
</body>
</html>