-
Notifications
You must be signed in to change notification settings - Fork 0
/
getModes.js
126 lines (72 loc) · 2.46 KB
/
getModes.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
var modeControl;
var modes= ["Party", "Goodnight", "Danger"];
function ModeControl(modess) {
//private
var current_mode = 1;
if (typeof modess == "undefined")
{
modess = [];
console.log("HERE");
}
var modes = modess;
for (i in modes) {
$("#modes").append("<div class='box' id ='mode_"+i+"'>"+modes[i]+"</div>");
}
setInterval(function() {
var id="#mode_"+current_mode;
if (!$(id).hasClass("selected"))
$(id).addClass("selected");
}, 1000/30);
//functions
this.getCurrentMode = function() {
return modes[current_mode];
}
this.selectNext = function() {
$("#mode_"+current_mode).removeClass("selected");
//alert("YO");
if (++current_mode >= modes.length) current_mode = 0;
}
this.selectPrev = function() {
$("#mode_"+current_mode).removeClass("selected");
//alert("YO");
if (--current_mode < 0 && modes.length != 0) current_mode = modes.length-1;
}
this.lock = function() {
//switch off
//switchOff(switches[current_switch].id)
//switches[current_switch].state = "off";
$("#mode_"+current_mode).removeClass("on");
activateDefaultMode();
}
this.unlock = function() {
var currMode = this.getCurrentMode();
console.log("Current mode = "+currMode);
if (currMode == "Party") activatePartyMode();
if (currMode == "Goodnight") activateGoodnightMode();
if (currMode == "Danger") activateDangerMode();
//switch on
//switchOn(switches[current_switch].id);
//switches[current_switch].state = "on";
$("#mode_"+current_mode).addClass("on");
}
}
function activatePartyMode() {
$.get("https://graph.api.smartthings.com/api/smartapps/installations/"+key+"/modes/party", function(data) {
// switchOn(data);
});
}
function activateDangerMode() {
$.get("https://graph.api.smartthings.com/api/smartapps/installations/"+key+"/modes/danger", function(data) {
// switchOn(data);
});
}
function activateGoodnightMode() {
$.get("https://graph.api.smartthings.com/api/smartapps/installations/"+key+"/modes/goodnight", function(data) {
// switchOn(data);
});
}
function activateDefaultMode() {
$.get("https://graph.api.smartthings.com/api/smartapps/installations/"+key+"/modes/default", function(data) {
// switchOn(data);
});
}