edit
[smartthings-infrastructure.git] / Methods / eventHandler.groovy
index eee7a25df54da0936718499ce3ca5237154570e8..59bb059fe9086f4f9b7dfa82ef55c024e37765d8 100644 (file)
@@ -9,21 +9,30 @@ def eventHandler(LinkedHashMap eventDataMap) {
        def isStateChange = eventDataMap["isStateChange"]
        def unit = eventDataMap["unit"]
        def data = eventDataMap["data"]
-       
-       for (int i = 0;i < eventList.size();i++) {
-               if (eventList[i] == name) {
-                       evt.add(new Event())
-                       evt[-1].value = value
-                       evt[-1].name = name
-                       evt[-1].deviceId = deviceId
-                       evt[-1].descriptionText = descriptionText
-                       evt[-1].displayed = displayed
-                       evt[-1].linkText = linkText
-                       evt[-1].displayName = linkText
-                       evt[-1].isStateChange = isStateChange
-                       evt[-1].unit = unit
-                       evt[-1].data = data
-                       functionList[i](evt[-1])
+
+       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)
+                       }
+                       else
+                               app2.functionList[i](event)
+               }
+       }
+
+       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) {
+                               String toCall = app1.functionList[i]
+                               app1."$toCall"(event)
+                       }
+                       else
+                               app1.functionList[i](event)
                }
        }
 }