f15a30072aeee0f4033dd80e65ee454cb4542a9f
[smartthings-infrastructure.git] / Button / Buttons.groovy
1 //Create a class for button
2 package Button
3 import Timer.SimulatedTimer
4
5 public class Buttons {
6         private int deviceNumbers
7         private List buttons
8         def sendEvent
9
10         //For one device(We cannot have obj.id)-> We should have obj[0].id
11         private String id = "buttonID0"
12         private String label = "button0"
13         private String displayName = "button0"
14         private String button = "pushed"
15         private int numberOfButtons = 4
16         
17                 
18         Buttons(Closure sendEvent, int deviceNumbers, boolean init) {
19                 this.sendEvent = sendEvent              
20                 this.deviceNumbers = deviceNumbers
21                 this.buttons = []
22
23                 if (init) {
24                         this.button = "pushed"
25                 } else {
26                         this.button = "held"
27                 }
28                 buttons.add(new Button(id, label, displayName, button, numberOfButtons))
29         }
30
31         //By Model Checker
32         def setValue(LinkedHashMap eventDataMap) {
33                 buttons[0].setValue(eventDataMap)
34                 sendEvent(eventDataMap)
35         }
36
37         //Methods for closures
38         def count(Closure Input) {
39                 buttons.count(Input)
40         }
41         def size() {
42                 buttons.size()
43         }
44         def each(Closure Input) {
45                 buttons.each(Input)
46         }
47         def sort(Closure Input) {
48                 buttons.sort(Input)
49         }
50         def find(Closure Input) {
51                 buttons.find(Input)
52         }
53         def collect(Closure Input) {
54                 buttons.collect(Input)
55         }
56
57
58         //methods
59         def eventsSince(Date dateObj) {
60                 return buttons[0].eventsSince()
61         }
62
63
64         def getAt(int ix) {
65                 buttons[ix]
66         }
67 }