Skip to content

Commit 1d078d2

Browse files
Control schedule mode from the web UI
1 parent c4ca476 commit 1d078d2

1 file changed

Lines changed: 42 additions & 3 deletions

File tree

public/index.html

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,19 @@
8080
inner.appendChild(button);
8181
outer.appendChild(inner);
8282
schlist.insertBefore(outer, addline);
83-
}
83+
}
84+
var label = "Enable Schedule";
85+
var action = enableSchedule;
86+
if (response.lights.mode == "auto") {
87+
label = "Disable Schedule";
88+
action = disableSchedule;
89+
}
90+
var buttons = document.getElementsByClassName ("modeButton");
91+
for (var i = 0; i < buttons.length; i++) {
92+
buttons[i].innerHTML = label;
93+
buttons[i].disabled = false;
94+
buttons[i].onclick = action;
95+
}
8496
}
8597

8698
function lightsUpdate (response) {
@@ -93,9 +105,12 @@
93105
lightsShow(response);
94106
}
95107

96-
function lightsRefresh () {
108+
function lightsRefresh (request) {
97109
var command = new XMLHttpRequest();
98-
command.open("GET", "/lights/status");
110+
if (request)
111+
command.open("GET", request);
112+
else
113+
command.open("GET", "/lights/status");
99114
command.onreadystatechange = function () {
100115
if (command.readyState === 4 && command.status === 200) {
101116
var response = JSON.parse(command.responseText);
@@ -140,6 +155,16 @@
140155
command.send(null);
141156
}
142157

158+
function doNothing() {}
159+
160+
function enableSchedule () {
161+
lightsRefresh ("/lights/enable");
162+
}
163+
164+
function disableSchedule () {
165+
lightsRefresh ("/lights/disable");
166+
}
167+
143168
window.onload = function() {
144169
lightsConfig();
145170
setInterval (lightsRefresh, 5000);
@@ -189,6 +214,20 @@
189214
<td><input type="checkbox" id="lightsat"></td>
190215
<td><button onclick="lightsAdd()">Add</button></td>
191216
</tr>
217+
<tr>
218+
<td></td>
219+
<td></td>
220+
<td></td>
221+
<td></td>
222+
<td></td>
223+
<td></td>
224+
<td></td>
225+
<td></td>
226+
<td></td>
227+
<td></td>
228+
<td></td>
229+
<td><button class="modeButton" disabled onclick="doNothing()">Loading..</button></td>
230+
</tr>
192231
</table>
193232
</body>
194233
</html>

0 commit comments

Comments
 (0)