Decreasing the number of required events for each device by mapping them to one singl...
[smartthings-infrastructure.git] / Methods / eventHandler.groovy
1 /////////////////////////////////////////////////////////////////////
2 def eventHandler(LinkedHashMap eventDataMap) {
3         def value = eventDataMap["value"]
4         def name = eventDataMap["name"]
5         def deviceId = eventDataMap["deviceId"]
6         def descriptionText = eventDataMap["descriptionText"]
7         def displayed = eventDataMap["displayed"]
8         def linkText = eventDataMap["linkText"]
9         def isStateChange = eventDataMap["isStateChange"]
10         def unit = eventDataMap["unit"]
11         def data = eventDataMap["data"]
12
13         for (int i = 0;i < app2.eventList.size();i++) {
14                 if (app2.eventList[i] == name) {
15                         def event = new Event(value, name, deviceId, descriptionText, displayed, linkText, linkText, isStateChange, unit, data)
16                         if (app2.functionList[i] instanceof String) {
17                                 String toCall = app2.functionList[i]
18                                 app2."$toCall"(event)
19                         }
20                         else
21                                 app2.functionList[i](event)
22                 }
23         }
24
25         for (int i = 0;i < app1.eventList.size();i++) {
26                 if (app1.eventList[i] == name) {
27                         def event = new Event(value, name, deviceId, descriptionText, displayed, linkText, linkText, isStateChange, unit, data)
28                         if (app1.functionList[i] instanceof String) {
29                                 String toCall = app1.functionList[i]
30                                 app1."$toCall"(event)
31                         }
32                         else
33                                 app1.functionList[i](event)
34                 }
35         }
36 }