Merge branch 'master' of ssh://plrg.eecs.uci.edu/home/git/smartthings-infrastructure
[smartthings-infrastructure.git] / AccelerationSensor / AccelerationSensor.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 AccelerationSensor {
9         private String id
10         private String label
11         private String displayName
12         private String acceleration
13         private String currentAcceleration
14         private String accelerationLatestValue
15
16         AccelerationSensor(String id, String label, String displayName, String acceleration, String accelerationLatestValue) {
17                 this.id = id
18                 this.label = label
19                 this.displayName = displayName
20                 this.acceleration = acceleration
21                 this.currentAcceleration = acceleration
22                 this.accelerationLatestValue = accelerationLatestValue
23         }
24
25         def setValue(String value) {
26                 println("the acceleration sensor with id:$id is triggered to $value!")
27                 this.accelerationLatestValue = value
28                 this.acceleration = value
29                 this.currentAcceleration = value
30         }
31
32         def statesSince() {
33                 def evtActive = [[name: "acceleration", value: "active", deviceId: "accelerationSensorID0", descriptionText: "",
34                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'],
35                                  [name: "acceleration.active", value: "active", deviceId: "accelerationSensorID0", descriptionText: "",
36                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
37                 def evtInactive = [[name: "acceleration", value: "inactive", deviceId: "accelerationSensorID0", descriptionText: "",
38                                     displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'],
39                                    [name: "acceleration.inactive", value: "inactive", deviceId: "accelerationSensorID0", descriptionText: "",
40                                     displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
41                 def init = Verify.getInt(0,4)
42                 def evtToSend = []
43                 if (init == 0) {//return empty set
44                         return evtToSend
45                 } else if (init == 1) {//send one active event
46                         evtActive.each{
47                                 evtToSend.add(it)
48                         }
49                         return evtToSend
50                 } else if (init == 2) {//send two active events
51                         evtActive.each{
52                                 evtToSend.add(it)
53                         }
54                         evtActive.each{
55                                 evtToSend.add(it)
56                         }
57                         return evtToSend
58                 } else if (init == 3) {//send one inactive event
59                         evtInactive.each{
60                                 evtToSend.add(it)
61                         }
62                         return evtToSend
63                 } else if (init == 4) {//send two inactive events
64                         evtInactive.each{
65                                 evtToSend.add(it)
66                         }
67                         evtInactive.each{
68                                 evtToSend.add(it)
69                         }
70                         return evtToSend
71                 }
72         }
73
74         def eventsSince() {
75                 def evtActive = [[name: "acceleration", value: "active", deviceId: "accelerationSensorID0", descriptionText: "",
76                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'],
77                                  [name: "acceleration.active", value: "active", deviceId: "accelerationSensorID0", descriptionText: "",
78                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
79                 def evtInactive = [[name: "acceleration", value: "inactive", deviceId: "accelerationSensorID0", descriptionText: "",
80                                     displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'],
81                                    [name: "acceleration.inactive", value: "inactive", deviceId: "accelerationSensorID0", descriptionText: "",
82                                     displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
83                 def init = Verify.getInt(0,4)
84                 def evtToSend = []
85                 if (init == 0) {//return empty set
86                         return evtToSend
87                 } else if (init == 1) {//send one active event
88                         evtActive.each{
89                                 evtToSend.add(it)
90                         }
91                         return evtToSend
92                 } else if (init == 2) {//send two active events
93                         evtActive.each{
94                                 evtToSend.add(it)
95                         }
96                         evtActive.each{
97                                 evtToSend.add(it)
98                         }
99                         return evtToSend
100                 } else if (init == 3) {//send one inactive event
101                         evtInactive.each{
102                                 evtToSend.add(it)
103                         }
104                         return evtToSend
105                 } else if (init == 4) {//send two inactive events
106                         evtInactive.each{
107                                 evtToSend.add(it)
108                         }
109                         evtInactive.each{
110                                 evtToSend.add(it)
111                         }
112                         return evtToSend
113                 }
114         }
115
116         
117         def currentValue(String deviceFeature) {
118                 if (deviceFeature == "acceleration") {
119                         return acceleration
120                 }
121         }
122
123         def latestValue(String deviceFeature) {
124                 if (deviceFeature == "acceleration") {
125                         return accelerationLatestValue
126                 }
127         }
128 }