X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=Methods%2Fsubscribe.groovy;h=b60cb4501457ad4bfad618d49072b9acd6c6b015;hb=91baad001ce2d84cf5eb1b5d3f62ce90a6c8b0a2;hp=730b76ac60bdc542a28f290a0e5b6f96c2cfa6c6;hpb=de35dfa319418baf7ba4bc2eeb4dbfc0fd20230a;p=smartthings-infrastructure.git diff --git a/Methods/subscribe.groovy b/Methods/subscribe.groovy index 730b76a..b60cb45 100644 --- a/Methods/subscribe.groovy +++ b/Methods/subscribe.groovy @@ -4,28 +4,65 @@ 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") + 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 + } else if ((event == "mode")||(event == "mode.away")||(event == "mode.home")||(event == "mode.night")) { + //This really should be fixed also... + event = "Location" + } + + 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 + } else if ((event == "mode")||(event == "mode.away")||(event == "mode.home")||(event == "mode.night")) { + event = "Location" + } + + 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) }