Fixing the previous commit bugs! Adding required classes + required methods
[smartthings-infrastructure.git] / Button / Buttons.groovy
diff --git a/Button/Buttons.groovy b/Button/Buttons.groovy
new file mode 100644 (file)
index 0000000..423b956
--- /dev/null
@@ -0,0 +1,65 @@
+//Create a class for button
+package Button
+import Timer.SimulatedTimer
+
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
+public class Buttons {
+       private int deviceNumbers
+       private List buttons
+       def sendEvent
+
+       //For one device(We cannot have obj.id)-> We should have obj[0].id
+       private String id = "buttonID0"
+       private String label = "button0"
+       private String displayName = "button0"
+       private String button = "pushed"
+       private int numberOfButtons = 4
+       
+               
+       Buttons(Closure sendEvent, int deviceNumbers) {
+               this.sendEvent = sendEvent              
+               this.deviceNumbers = deviceNumbers
+               this.buttons = []
+
+               buttons.add(new Button(id, label, displayName, button, numberOfButtons))
+       }
+
+       //By Model Checker
+       def setValue(LinkedHashMap eventDataMap) {
+               buttons[0].setValue(eventDataMap)
+               sendEvent(eventDataMap)
+       }
+
+       //Methods for closures
+       def count(Closure Input) {
+               buttons.count(Input)
+       }
+       def size() {
+               buttons.size()
+       }
+       def each(Closure Input) {
+               buttons.each(Input)
+       }
+       def sort(Closure Input) {
+               buttons.sort(Input)
+       }
+       def find(Closure Input) {
+               buttons.find(Input)
+       }
+       def collect(Closure Input) {
+               buttons.collect(Input)
+       }
+
+
+       //methods
+       def eventsSince(Date dateObj) {
+               return buttons[0].eventsSince()
+       }
+
+
+       def getAt(int ix) {
+               buttons[ix]
+       }
+}