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