Removing getXXX methods + properties. Adding getProperty feature to SmartThing(s)
[smartthings-infrastructure.git] / Methods / subscribe.groovy
index 730b76ac60bdc542a28f290a0e5b6f96c2cfa6c6..d77c88f60580917b2def0888ac39a1fa495eee1d 100644 (file)
@@ -4,28 +4,60 @@ def subscribe(Object obj, Closure FunctionToCall) {
        if (obj == app) {
                objectList.add(obj)
                eventList.add("Touched")
+                valueList.add("")
                functionList.add(FunctionToCall)
        } else if (obj == location) {
                objectList.add(obj)
-               eventList.add("Location")
+               eventList.add("mode")
+                valueList.add("")
                functionList.add(FunctionToCall)
        }
 }
+
 ////subscribe(obj, event, func)
 def subscribe(Object obj, String event, Closure FunctionToCall) {
-       objectList.add(obj)
-       eventList.add(event)
-       functionList.add(FunctionToCall)
+    if (event == "tamper.tampered") {
+       event = "contact"      //This really should be its own name
+    }
+    
+    int dot = event.indexOf('.')
+    String name = ""
+    String value = ""
+    if (dot != -1) {
+      name = event.substring(0, dot)
+      value = event.substring(dot + 1)
+    } else {
+      name = event
+    }
+
+    objectList.add(obj)
+    eventList.add(name)
+    functionList.add(FunctionToCall)
+    valueList.add(value)
 }
 ////subscribe(obj, event, nameOfFunc)
-def subscribe(Object obj, String event, String nameOfFunction) {
-       objectList.add(obj)
-       eventList.add(event)
-       functionList.add(nameOfFunction)
+def subscribe(Object obj, String event, String FunctionToCall) {
+    if (event == "tamper.tampered") {
+       event = "contact"      //This really should be its own name
+    }
+
+    int dot = event.indexOf('.')
+    String name = ""
+    String value = ""
+    if (dot != -1) {
+      name = event.substring(0, dot)
+      value = event.substring(dot + 1)
+    } else {
+      name = event
+    }
+
+    objectList.add(obj)
+    eventList.add(name)
+    functionList.add(FunctionToCall)
+    valueList.add(value)
 }
+
 ////subscribe(obj, event, func, data)
 def subscribe(Object obj, String event, Closure FunctionToCall, LinkedHashMap metaData) {
-       objectList.add(obj)     
-       eventList.add(event)
-       functionList.add(FunctionToCall)
+       subscribe(obj, event, FunctionToCall)
 }