Some minor changes!
[smartthings-infrastructure.git] / CarbonMonoxideDetector / CarbonMonoxideDetectors.groovy
index 9a682610d0814b45b434d7ab332b4b56c8d519aa..ba828d7d0542a73be5dee54e167adceb4f14e84f 100644 (file)
@@ -2,9 +2,6 @@
 package CarbonMonoxideDetector
 import Timer.SimulatedTimer
 
-//JPF's Verify API
-import gov.nasa.jpf.vm.Verify
-
 public class CarbonMonoxideDetectors {
        private int deviceNumbers
        private List carbonMonoxideDetectors
@@ -19,32 +16,30 @@ public class CarbonMonoxideDetectors {
        private String carbonMonoxideLatestValue = "clear"
 
                
-       CarbonMonoxideDetectors(Closure sendEvent, int deviceNumbers) {
+       CarbonMonoxideDetectors(Closure sendEvent, int deviceNumbers, boolean init) {
                this.sendEvent = sendEvent              
                this.deviceNumbers = deviceNumbers
                this.carbonMonoxideDetectors = []
                
-               /*def init = Verify.getInt(0,2)
-               if (init == 0) {
+               if (init) {
                        this.carbonMonoxide = "clear"
+                       this.currentCarbonMonoxideValue = "clear"
                        this.carbonMonoxideLatestValue = "clear"
                } else if (init == 1) {
                        this.carbonMonoxide = "detected"
+                       this.currentCarbonMonoxideValue = "detected"
                        this.carbonMonoxideLatestValue = "detected"
-               } else {
-                       this.carbonMonoxide = "tested"
-                       this.carbonMonoxideLatestValue = "tested"               
-               }*/
+               }
                carbonMonoxideDetectors.add(new CarbonMonoxideDetector(id, label, displayName, this.currentCarbonMonoxideValue, this.carbonMonoxideLatestValue))
        }
 
        //By Model Checker
        def setValue(LinkedHashMap eventDataMap) {
                if (eventDataMap["value"] != carbonMonoxideDetectors[0].currentCarbonMonoxideValue) {
+                       this.carbonMonoxideLatestValue = eventDataMap["value"]
+                       this.carbonMonoxide = eventDataMap["value"]
+                       this.currentCarbonMonoxideValue = eventDataMap["value"]
                        carbonMonoxideDetectors[0].setValue(eventDataMap["value"])
-                       this.carbonMonoxideLatestValue = carbonMonoxideDetectors[0].carbonMonoxideLatestValue
-                       this.carbonMonoxide = carbonMonoxideDetectors[0].currentCarbonMonoxideValue
-                       this.currentCarbonMonoxideValue = carbonMonoxideDetectors[0].currentCarbonMonoxideValue
                        sendEvent(eventDataMap)
                }
        }
@@ -62,6 +57,9 @@ public class CarbonMonoxideDetectors {
        def find(Closure Input) {
                carbonMonoxideDetectors.find(Input)
        }
+       def sort(Closure Input) {
+               carbonMonoxideDetectors.sort(Input)
+       }
        def collect(Closure Input) {
                carbonMonoxideDetectors.collect(Input)
        }