db90c564479fd7d837faeb91818dfd4822582c45
[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         AccelerationSensors(Closure sendEvent, int deviceNumbers) {
23                 this.sendEvent = sendEvent              
24                 this.deviceNumbers = deviceNumbers
25                 this.accelerationSensors = []
26
27                 /*def init = Verify.getBoolean()
28                 if (init) {
29                         this.acceleration = "inactive"
30                         this.accelerationLatestValue = "inactive"
31                 } else {
32                         this.acceleration = "active"
33                         this.accelerationLatestValue = "active"
34                 }*/
35                 accelerationSensors.add(new AccelerationSensor(id, label, displayName, this.acceleration, this.accelerationLatestValue))
36         }
37
38         //By Model Checker
39         def setValue(LinkedHashMap eventDataMap) {
40                 if (eventDataMap["value"] != accelerationSensors[0].acceleration) {
41                         accelerationSensors[0].setValue(eventDataMap["value"])
42                         this.accelerationLatestValue = accelerationSensors[0].accelerationLatestValue
43                         this.acceleration = accelerationSensors[0].acceleration
44                         this.currentAcceleration = accelerationSensors[0].acceleration
45                         sendEvent(eventDataMap)
46                 }
47         }
48
49         //Methods for closures
50         def count(Closure Input) {
51                 accelerationSensors.count(Input)
52         }
53         def size() {
54                 accelerationSensors.size()
55         }
56         def each(Closure Input) {
57                 accelerationSensors.each(Input)
58         }
59         def find(Closure Input) {
60                 accelerationSensors.find(Input)
61         }
62         def collect(Closure Input) {
63                 accelerationSensors.collect(Input)
64         }
65
66
67         def currentValue(String deviceFeature) {
68                 accelerationSensors[0].currentValue(deviceFeature)//It is called if we have only one device
69         }
70
71         def latestValue(String deviceFeature) {
72                 accelerationSensors[0].latestValue(deviceFeature)//It is called if we have only one device
73         }
74
75         def statesSince(String info, Date dateObj) {
76                 return accelerationSensors[0].statesSince(info, dateObj)
77         }
78
79         def getAt(int ix) {
80                 accelerationSensors[ix]
81         }
82 }