X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=Methods%2Fsubscribe.groovy;h=a387375c849ab7ff53354342977bf939ff4316c3;hb=edbe95f550e8d70ffc92f9afaf79b80ed9243c53;hp=c7104fc2e1b9094386308f4732684c85c541b47a;hpb=c0cb655866633825464d2af2b572488b0f2e18d0;p=smartthings-infrastructure.git diff --git a/Methods/subscribe.groovy b/Methods/subscribe.groovy index c7104fc..a387375 100644 --- a/Methods/subscribe.groovy +++ b/Methods/subscribe.groovy @@ -1,19 +1,72 @@ ///////////////////////////////////////////////////////////////////// -////subscribe(app, func) -def subscribe(Object Obj, Closure Input) { - ObjectList.add(Obj) - EventList.add("Touched") - FunctionList.add(Input) +////subscribe(obj, func) +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, string, func) -def subscribe(Object Obj, String S, Closure Input) { - ObjectList.add(Obj) - EventList.add(S) - FunctionList.add(Input) + +////subscribe(obj, event, func) +def subscribe(Object obj, String event, Closure 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" + } else if (event == "unlocked") { + return + } + + 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, string, func, hashmap) -def subscribe(Object Obj, String S, Closure Input, LinkedHashMap LHM) { - ObjectList.add(Obj) - EventList.add(S) - FunctionList.add(Input) +////subscribe(obj, event, nameOfFunc) +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" + } else if (event == "unlocked") { + return + } + + 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) { + subscribe(obj, event, FunctionToCall) }