Merge branch 'master' of ssh://plrg.eecs.uci.edu/home/git/smartthings-infrastructure
[smartthings-infrastructure.git] / AccelerationSensor / AccelerationSensors.groovy
1 //Create a class for acceleration sensor
2 package AccelerationSensor
3 import Timer.SimulatedTimer
4
5 //JPF's Verify API
6 import gov.nasa.jpf.vm.Verify
7
8 public class AccelerationSensors {
9         private int deviceNumbers
10         private List accelerationSensors
11         def sendEvent
12
13         //For one device(We cannot have obj.id)-> We should have obj[0].id
14         private String id = "accelerationSensorID0"
15         private String label = "accelerationSensor0"
16         private String displayName = "accelerationSensor0"
17         private String acceleration = "inactive"
18         private String currentAcceleration = "inactive"
19         private String accelerationLatestValue = "inactive"
20         
21
22                 
23         AccelerationSensors(Closure sendEvent, int deviceNumbers) {
24                 this.sendEvent = sendEvent              
25                 this.deviceNumbers = deviceNumbers
26                 this.accelerationSensors = []
27
28                 /*def init = Verify.getBoolean()
29                 if (init) {
30                         this.acceleration = "inactive"
31                         this.accelerationLatestValue = "inactive"
32                 } else {
33                         this.acceleration = "active"
34                         this.accelerationLatestValue = "active"
35                 }*/
36                 accelerationSensors.add(new AccelerationSensor(id, label, displayName, this.acceleration, this.accelerationLatestValue))
37         }
38
39         //By Model Checker
40         def setValue(LinkedHashMap eventDataMap) {
41                 if (eventDataMap["value"] != accelerationSensors[0].acceleration) {
42                         this.accelerationLatestValue = eventDataMap["value"]
43                         this.acceleration = eventDataMap["value"]
44                         this.currentAcceleration = eventDataMap["value"]
45                         accelerationSensors[0].setValue(eventDataMap["value"])
46                         sendEvent(eventDataMap)
47                 }
48         }
49
50         //Methods for closures
51         def count(Closure Input) {
52                 accelerationSensors.count(Input)
53         }
54         def size() {
55                 accelerationSensors.size()
56         }
57         def each(Closure Input) {
58                 accelerationSensors.each(Input)
59         }
60         def sort(Closure Input) {
61                 accelerationSensors.each(Input)
62         }
63         def find(Closure Input) {
64                 accelerationSensors.find(Input)
65         }
66         def collect(Closure Input) {
67                 accelerationSensors.collect(Input)
68         }
69
70
71         def currentValue(String deviceFeature) {
72                 accelerationSensors[0].currentValue(deviceFeature)//It is called if we have only one device
73         }
74
75         def latestValue(String deviceFeature) {
76                 accelerationSensors[0].latestValue(deviceFeature)//It is called if we have only one device
77         }
78
79         def statesSince(String info, Date dateObj) {
80                 return accelerationSensors[0].statesSince(info, dateObj)
81         }
82
83         def getAt(int ix) {
84                 accelerationSensors[ix]
85         }
86 }