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