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