Adding manual transaction feature to new infrastructure
[smartthings-infrastructure.git] / Methods / eventHandler.groovy
index 59bb059fe9086f4f9b7dfa82ef55c024e37765d8..1ce9048273acf8d3bf91ca3c137d31fc861a5c25 100644 (file)
@@ -9,11 +9,16 @@ def eventHandler(LinkedHashMap eventDataMap) {
        def isStateChange = eventDataMap["isStateChange"]
        def unit = eventDataMap["unit"]
        def data = eventDataMap["data"]
+       def manualEventsName = ["Touched", "button", "nfcTouch", "threeAxis"]
 
+       def event = new Event(value, name, deviceId, descriptionText, displayed, linkText, linkText, isStateChange, unit, data)
+
+       stack.push(manualEventsName.contains(name))
+       event.setManualTransaction(stack[0])
+       
        for (int i = 0;i < app2.eventList.size();i++) {
                if (app2.eventList[i] == name &&
                    (app2.valueList[i] == "" || app2.valueList[i] == value)) {
-                       def event = new Event(value, name, deviceId, descriptionText, displayed, linkText, linkText, isStateChange, unit, data)
                        if (app2.functionList[i] instanceof String) {
                                String toCall = app2.functionList[i]
                                app2."$toCall"(event)
@@ -26,8 +31,7 @@ def eventHandler(LinkedHashMap eventDataMap) {
        for (int i = 0;i < app1.eventList.size();i++) {
                if (app1.eventList[i] == name &&
                    (app1.valueList[i] == "" || app1.valueList[i] == value)) {
-                        def event = new Event(value, name, deviceId, descriptionText, displayed, linkText, linkText, isStateChange, unit, data)
-                       if (app1.functionList[i] instanceof String) {
+                        if (app1.functionList[i] instanceof String) {
                                String toCall = app1.functionList[i]
                                app1."$toCall"(event)
                        }
@@ -35,4 +39,8 @@ def eventHandler(LinkedHashMap eventDataMap) {
                                app1.functionList[i](event)
                }
        }
+
+       stack.pop()
+       if (stack[0] != null)
+               event.setManualTransaction(stack[0])
 }