1 //Create a class for beacon sensor
3 import Timer.SimulatedTimer
5 public class BeaconSensors {
6 private int deviceNumbers
7 private List beaconSensors
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"
19 BeaconSensors(Closure sendEvent, int deviceNumbers, boolean init) {
20 this.sendEvent = sendEvent
21 this.deviceNumbers = deviceNumbers
22 this.beaconSensors = []
25 this.presence = "not present"
26 this.currentPresence = "not present"
27 this.presenceLatestValue = "not present"
29 this.presence = "present"
30 this.currentPresence = "present"
31 this.presenceLatestValue = "present"
33 beaconSensors.add(new BeaconSensor(id, label, displayName, this.presence, this.presenceLatestValue))
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)
47 //Methods for closures
48 def count(Closure Input) {
49 beaconSensors.count(Input)
54 def each(Closure Input) {
55 beaconSensors.each(Input)
57 def sort(Closure Input) {
58 beaconSensors.sort(Input)
60 def find(Closure Input) {
61 beaconSensors.find(Input)
63 def collect(Closure Input) {
64 beaconSensors.collect(Input)
68 def currentValue(String deviceFeature) {
69 beaconSensors[0].currentValue(deviceFeature)//It is called if we have only one device
72 def latestValue(String deviceFeature) {
73 beaconSensors[0].latestValue(deviceFeature)//It is called if we have only one device