A bug in Thermostat group
[smartthings-infrastructure.git] / BeaconSensor / BeaconSensors.groovy
index 24bcfc8dfa3e6c57b3de0afced91b174442ded63..4550965ad876a28d4c30425ee5fb257a4914d145 100644 (file)
@@ -16,21 +16,30 @@ public class BeaconSensors {
        private String presenceLatestValue = "not present"
 
                
-       BeaconSensors(Closure sendEvent, int deviceNumbers) {
+       BeaconSensors(Closure sendEvent, int deviceNumbers, boolean init) {
                this.sendEvent = sendEvent              
                this.deviceNumbers = deviceNumbers
                this.beaconSensors = []
 
+               if (init) {
+                       this.presence = "not present"
+                       this.currentPresence = "not present"
+                       this.presenceLatestValue = "not present"
+               } else {
+                       this.presence = "present"
+                       this.currentPresence = "present"
+                       this.presenceLatestValue = "present"
+               }
                beaconSensors.add(new BeaconSensor(id, label, displayName, this.presence, this.presenceLatestValue))
        }
 
        //By Model Checker
        def setValue(LinkedHashMap eventDataMap) {
                if (eventDataMap["value"] != beaconSensors[0].presence) {
+                       this.presenceLatestValue = eventDataMap["value"]
+                       this.presence = eventDataMap["value"]
+                       this.currentPresence = eventDataMap["value"]
                        beaconSensors[0].setValue(eventDataMap["value"])
-                       this.presenceLatestValue = beaconSensors[0].presenceLatestValue
-                       this.presence = beaconSensors[0].presence
-                       this.currentPresence = beaconSensors[0].presence
                        sendEvent(eventDataMap)
                }
        }
@@ -45,6 +54,9 @@ public class BeaconSensors {
        def each(Closure Input) {
                beaconSensors.each(Input)
        }
+       def sort(Closure Input) {
+               beaconSensors.sort(Input)
+       }
        def find(Closure Input) {
                beaconSensors.find(Input)
        }