Merge branch 'master' of ssh://plrg.eecs.uci.edu/home/git/smartthings-infrastructure
[smartthings-infrastructure.git] / Momentary / Momentaries.groovy
1 //Create a class for momentory switch device
2 package Momentary
3 import Timer.SimulatedTimer
4
5 //JPF's Verify API
6 import gov.nasa.jpf.vm.Verify
7
8 public class Momentaries {
9         int deviceNumbers       
10         List momentaries
11         def sendEvent
12
13         //If we have only one device
14         private String id = "momentaryID0"
15         private String label = "momentary0"
16         private String displayName = "momentary0"
17
18         Momentaries(Closure sendEvent, int deviceNumbers) {
19                 this.sendEvent = sendEvent
20                 this.deviceNumbers = deviceNumbers
21                 this.momentaries = []
22                 
23                 /*def init = Verify.getBoolean()
24                 if (init) {
25                         this.doorState = "closed"
26                         this.doorLatestValue = "closed"
27                 } else {
28                         this.doorState = "open"
29                         this.doorLatestValue = "open"
30                 }*/
31                 momentaries.add(new Momentary(sendEvent, id, label, displayName))
32         }
33
34         //Methods for closures
35         def count(Closure Input) {
36                 momentaries.count(Input)
37         }
38         def size() {
39                 momentaries.size()
40         }
41         def each(Closure Input) {
42                 momentaries.each(Input)
43         }
44         def find(Closure Input) {
45                 momentaries.find(Input)
46         }
47         def sort(Closure Input) {
48                 momentaries.sort(Input)
49         }
50         def collect(Closure Input) {
51                 momentaries.collect(Input)
52         }
53
54         //By Apps
55         def push() {
56                 momentaries[0].push()
57         }
58
59         //By Model Checker
60         def setValue(LinkedHashMap eventDataMap) {
61                 momentaries[0].setValue(eventDataMap["value"])
62                 sendEvent(eventDataMap)
63         }
64
65         def getAt(int ix) {
66                 momentaries[ix]
67         }
68 }