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