Commenting out the Verify API calls in the object instantiation to avoid state explos...
[smartthings-infrastructure.git] / StepSensor / StepSensors.groovy
1 //Create a class for step sensor
2 package StepSensor
3 import Timer.SimulatedTimer
4
5 //JPF's Verify API
6 import gov.nasa.jpf.vm.Verify
7
8 public class StepSensors {
9         private int deviceNumbers
10         private List stepSensors
11         def sendEvent
12
13         //For one device(We cannot have obj.id)-> We should have obj[0].id
14         private String id = "stepSensorID0"
15         private String label = "stepSensor0"
16         private String displayName = "stepSensor0"
17         private int goal = 1000
18         private int steps = 0
19
20                 
21         StepSensors(Closure sendEvent, int deviceNumbers) {
22                 this.sendEvent = sendEvent              
23                 this.deviceNumbers = deviceNumbers
24                 this.stepSensors = []
25
26                 /*def initGoal = Verify.getIntFromList(1000, 2000, 3000)
27                 this.goal = initGoal
28                 def initSteps = Verify.getIntFromList(0, 1, 2)
29                 this.steps = initSteps*/
30
31                 stepSensors.add(new StepSensor(id, label, displayName, this.steps, this.goal))
32         }
33
34         //By Model Checker
35         def setValue(LinkedHashMap eventDataMap) {
36                 if (eventDataMap["name"] == "steps") {
37                         if (eventDataMap["value"] != stepSensors[0].steps) {
38                                 stepSensors[0].setValue(eventDataMap["value"], "steps")
39                                 this.steps = stepSensors[0].steps
40                                 sendEvent(eventDataMap)
41                         }
42                 } else if (eventDataMap["value"] == "goal") {
43                         if (eventDataMap["value"] != stepSensors[0].goal) {
44                                 stepSensors[0].setValue(eventDataMap["value"], "goal")
45                                 this.goal = stepSensors[0].goal
46                                 sendEvent(eventDataMap)
47                         }
48                 }
49         }
50
51         //Methods for closures
52         def count(Closure Input) {
53                 stepSensors.count(Input)
54         }
55         def size() {
56                 stepSensors.size()
57         }
58         def each(Closure Input) {
59                 stepSensors.each(Input)
60         }
61         def find(Closure Input) {
62                 stepSensors.find(Input)
63         }
64         def collect(Closure Input) {
65                 stepSensors.collect(Input)
66         }
67
68
69         def currentValue(String deviceFeature) {
70                 stepSensors[0].currentValue(deviceFeature)//It is called if we have only one device
71         }
72
73         def getAt(int ix) {
74                 stepSensors[ix]
75         }
76 }