Solving conflicts
[smartthings-infrastructure.git] / SleepSensor / SleepSensors.groovy
index 269a419e2212b28945b4514ec31cd91e0e0a9f7f..0db103302ed0869fbc2c8170ec124d9b34645f4a 100644 (file)
@@ -14,19 +14,24 @@ public class SleepSensors {
        private String sleeping = "sleeping"
 
                
-       SleepSensors(Closure sendEvent, int deviceNumbers) {
+       SleepSensors(Closure sendEvent, int deviceNumbers, boolean init) {
                this.sendEvent = sendEvent              
                this.deviceNumbers = deviceNumbers
                this.sleepSensors = []
 
+               if (init) {
+                       this.sleeping = "sleeping"
+               } else {
+                       this.sleeping = "not sleeping"
+               }
                sleepSensors.add(new SleepSensor(id, label, displayName, this.sleeping))
        }
 
        //By Model Checker
        def setValue(LinkedHashMap eventDataMap) {
                if (eventDataMap["value"] != sleepSensors[0].sleeping) {
+                       this.sleeping = eventDataMap["value"]
                        sleepSensors[0].setValue(eventDataMap["value"])
-                       this.sleeping = sleepSensors[0].sleeping
                        sendEvent(eventDataMap)
                }
        }
@@ -44,6 +49,9 @@ public class SleepSensors {
        def find(Closure Input) {
                sleepSensors.find(Input)
        }
+       def sort(Closure Input) {
+               sleepSensors.sort(Input)
+       }
        def collect(Closure Input) {
                sleepSensors.collect(Input)
        }