8ece0c6db1864dafdc25036f103f982618f7b729
[smartthings-infrastructure.git] / AeonKeyFob / AeonKeyFob.groovy
1 //Create a class for aeon key fob
2 package AeonKeyFob
3 import Timer.SimulatedTimer
4
5 public class AeonKeyFob {
6         private String id
7         private String label
8         private String displayName
9         private List events = []
10         private List timeOfEvents = []
11
12         AeonKeyFob(String id, String label, String displayName) {
13                 this.id = id
14                 this.label = label
15                 this.displayName = displayName
16         }
17
18         def setValue(LinkedHashMap eventDataMap) {
19                 def data = eventDataMap["data"]
20                 def value = eventDataMap["value"]
21                 println("the button with number $data is $value!")
22                 this.events.add(eventDataMap)
23                 this.timeOfEvents.add(System.currentTimeMillis())
24         }
25
26         def eventsSince(Date dateObj) {
27                 def List happenedEvents = []
28                 def sinceThen = dateObj.time
29                 for (int i = 0;i < timeOfEvents.size();i++) {
30                         if (timeOfEvents[i]>=sinceThen)
31                                 happenedEvents.add(events[i])
32                 }
33                 return happenedEvents
34         }
35 }