Adding event for Power as variation is needed in power values.
[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                 def evtInactive = [[name: "acceleration", value: "inactive", deviceId: "accelerationSensorID0", descriptionText: "",
36                                     displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
37                 def init = Verify.getInt(0,4)
38                 def evtToSend = []
39                 if (init == 0) {//return empty set
40                         return evtToSend
41                 } else if (init == 1) {//send one active event
42                         evtActive.each{
43                                 evtToSend.add(it)
44                         }
45                         return evtToSend
46                 } else if (init == 2) {//send two active events
47                         evtActive.each{
48                                 evtToSend.add(it)
49                         }
50                         evtActive.each{
51                                 evtToSend.add(it)
52                         }
53                         return evtToSend
54                 } else if (init == 3) {//send one inactive event
55                         evtInactive.each{
56                                 evtToSend.add(it)
57                         }
58                         return evtToSend
59                 } else if (init == 4) {//send two inactive events
60                         evtInactive.each{
61                                 evtToSend.add(it)
62                         }
63                         evtInactive.each{
64                                 evtToSend.add(it)
65                         }
66                         return evtToSend
67                 }
68         }
69
70         def eventsSince() {
71                 def evtActive = [[name: "acceleration", value: "active", deviceId: "accelerationSensorID0", descriptionText: "",
72                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
73                 def evtInactive = [[name: "acceleration", value: "inactive", deviceId: "accelerationSensorID0", descriptionText: "",
74                                     displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
75                 def init = Verify.getInt(0,4)
76                 def evtToSend = []
77                 if (init == 0) {//return empty set
78                         return evtToSend
79                 } else if (init == 1) {//send one active event
80                         evtActive.each{
81                                 evtToSend.add(it)
82                         }
83                         return evtToSend
84                 } else if (init == 2) {//send two active events
85                         evtActive.each{
86                                 evtToSend.add(it)
87                         }
88                         evtActive.each{
89                                 evtToSend.add(it)
90                         }
91                         return evtToSend
92                 } else if (init == 3) {//send one inactive event
93                         evtInactive.each{
94                                 evtToSend.add(it)
95                         }
96                         return evtToSend
97                 } else if (init == 4) {//send two inactive events
98                         evtInactive.each{
99                                 evtToSend.add(it)
100                         }
101                         evtInactive.each{
102                                 evtToSend.add(it)
103                         }
104                         return evtToSend
105                 }
106         }
107
108         
109         def currentValue(String deviceFeature) {
110                 if (deviceFeature == "acceleration") {
111                         return acceleration
112                 }
113         }
114
115         def latestValue(String deviceFeature) {
116                 if (deviceFeature == "acceleration") {
117                         return accelerationLatestValue
118                 }
119         }
120 }