Handle plain unlock
[smartthings-infrastructure.git] / Methods / subscribe.groovy
1 /////////////////////////////////////////////////////////////////////
2 ////subscribe(obj, func)
3 def subscribe(Object obj, Closure FunctionToCall) {
4         if (obj == app) {
5                 objectList.add(obj)
6                 eventList.add("Touched")
7                 valueList.add("")
8                 functionList.add(FunctionToCall)
9         } else if (obj == location) {
10                 objectList.add(obj)
11                 eventList.add("Location")
12                 valueList.add("")
13                 functionList.add(FunctionToCall)
14         }
15 }
16
17 ////subscribe(obj, event, func)
18 def subscribe(Object obj, String event, Closure FunctionToCall) {
19     if (event == "tamper.tampered") {
20        event = "contact"      //This really should be its own name
21     } else if ((event == "mode")||(event == "mode.away")||(event == "mode.home")||(event == "mode.night")) {
22        //This really should be fixed also...
23        event = "Location"
24     } else if (event == "unlocked") {
25       return
26     }
27     
28     int dot = event.indexOf('.')
29     String name = ""
30     String value = ""
31     if (dot != -1) {
32       name = event.substring(0, dot)
33       value = event.substring(dot + 1)
34     } else {
35       name = event
36     }
37
38     objectList.add(obj)
39     eventList.add(name)
40     functionList.add(FunctionToCall)
41     valueList.add(value)
42 }
43 ////subscribe(obj, event, nameOfFunc)
44 def subscribe(Object obj, String event, String FunctionToCall) {
45     if (event == "tamper.tampered") {
46        event = "contact"      //This really should be its own name
47     } else if ((event == "mode")||(event == "mode.away")||(event == "mode.home")||(event == "mode.night")) {
48        event = "Location"
49     } else if (event == "unlocked") {
50        return
51     }
52
53     int dot = event.indexOf('.')
54     String name = ""
55     String value = ""
56     if (dot != -1) {
57       name = event.substring(0, dot)
58       value = event.substring(dot + 1)
59     } else {
60       name = event
61     }
62
63     objectList.add(obj)
64     eventList.add(name)
65     functionList.add(FunctionToCall)
66     valueList.add(value)
67 }
68
69 ////subscribe(obj, event, func, data)
70 def subscribe(Object obj, String event, Closure FunctionToCall, LinkedHashMap metaData) {
71         subscribe(obj, event, FunctionToCall)
72 }