-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalls.js
80 lines (63 loc) · 2.16 KB
/
calls.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
var dimmers = []
function call(api_call) {
fetch(api_call, {mode: "no-cors"})
.then(response => {
console.log(response)
});
}
class Relay {
static toggle(ip, index) {
call(`http://${ip}/relay/${index}?turn=toggle`)
}
static on(ip, index) {
call(`http://${ip}/relay/${index}?turn=on`)
}
static off(ip, index) {
call(`http://${ip}/relay/${index}?turn=off`)
}
}
var Control = {
Shelly: {
Roller: {
open: function (ip, index) {
call(`http://${ip}/roller/${index}?go=open`)
},
close: function (ip, index) {
call(`http://${ip}/roller/${index}?go=close`)
}
},
Relay: {
toggle: function (ip, index) {
call(`http://${ip}/relay/${index}?turn=toggle`)
},
on: function (ip, index) {
call(`http://${ip}/relay/${index}?turn=on`)
},
off: function (ip, index) {
call(`http://${ip}/relay/${index}?turn=off`)
}
},
Dimmer: {
dim: function (ip, index, brightness) {
call(`http://${ip}/light/${index}?brightness=${brightness}`)
},
on: function (ip, index) {
call(`http://${ip}/light/${index}?turn=on`)
},
off: function (ip, index) {
call(`http://${ip}/light/${index}?turn=off`)
}
}
}
}
function dimmer(ip, index) {
console.log(ip, index)
let dimmerid = `${ip}-${index}`
document.getElementById(dimmerid).innerHTML = `<input type='range' min='1' max='100' id='slider-${dimmerid}'> <output id='display-${dimmerid}'></output>`
document.getElementById(`slider-${dimmerid}`).addEventListener('input', function () {
document.getElementById(`display-${dimmerid}`).innerHTML = document.getElementById(`slider-${dimmerid}`).value
}, false)
document.getElementById(`slider-${dimmerid}`).addEventListener('change', function () {
Control.Shelly.Dimmer.dim(ip, index, document.getElementById(`slider-${dimmerid}`).value)
}, false)
}