Changing Verify API call scheme for device handlers.
[smartthings-infrastructure.git] / SmokeDetector / SmokeDetectors.groovy
index e9d5da2f67b6c87057cc915d970fb9dbb83a1dc1..d2c61291ae4e0a3b023af747fd68886f302d2710 100644 (file)
@@ -2,9 +2,6 @@
 package SmokeDetector
 import Timer.SimulatedTimer
 
-//JPF's Verify API
-import gov.nasa.jpf.vm.Verify
-
 public class SmokeDetectors {
        private int deviceNumbers
        private List smokeDetectors
@@ -17,35 +14,66 @@ public class SmokeDetectors {
        private String smoke = "clear"
        private String currentSmokeValue = "clear"
        private String smokeLatestValue = "clear"
+       private String carbonMonoxide = "clear"
+       private String currentCarbonMonoxideValue = "clear"
+       private String carbonMonoxideLatestValue = "clear"
+       private int battery = 50
+    private int batteryValue = 50
+       private int batteryLatestValue = 50
 
                
-       SmokeDetectors(Closure sendEvent, int deviceNumbers) {
+       SmokeDetectors(Closure sendEvent, int deviceNumbers, boolean init) {
                this.sendEvent = sendEvent              
                this.deviceNumbers = deviceNumbers
                this.smokeDetectors = []
 
-               def init = Verify.getInt(0,2)
-               if (init == 0) {
+               if (init) {
                        this.currentSmokeValue = "clear"
                        this.smokeLatestValue = "clear"
-               } else if (init == 1) {
+                       this.carbonMonoxide = "clear"
+                       this.currentCarbonMonoxideValue = "clear"
+                       this.carbonMonoxideLatestValue = "clear"
+                       this.battery = 50
+                       this.batteryValue = 50
+                       this.batteryLatestValue = 50
+               } else {
                        this.currentSmokeValue = "detected"
                        this.smokeLatestValue = "detected"
-               } else {
-                       this.currentSmokeValue = "tested"
-                       this.smokeLatestValue = "tested"                
+                       this.carbonMonoxide = "detected"
+                       this.currentCarbonMonoxideValue = "detected"
+                       this.carbonMonoxideLatestValue = "detected"
+                       this.battery = 60
+                       this.batteryValue = 60
+                       this.batteryLatestValue = 60
                }
-               smokeDetectors.add(new SmokeDetector(id, label, displayName, this.currentSmokeValue, this.smokeLatestValue))
+               smokeDetectors.add(new SmokeDetector(id, label, displayName, this.currentSmokeValue, this.smokeLatestValue, this.carbonMonoxide, this.carbonMonoxideLatestValue, this.battery))
        }
 
        //By Model Checker
        def setValue(LinkedHashMap eventDataMap) {
-               if (eventDataMap["value"] != smokeDetectors[0].currentSmokeValue) {
-                       smokeDetectors[0].setValue(eventDataMap["value"])
-                       this.smokeLatestValue = smokeDetectors[0].smokeLatestValue
-                       this.smoke = smokeDetectors[0].currentSmokeValue
-                       this.currentSmokeValue = smokeDetectors[0].currentSmokeValue
-                       sendEvent(eventDataMap)
+               if (eventDataMap["name"].contains("smoke")) {
+                       if (eventDataMap["value"] != smokeDetectors[0].currentSmokeValue) {
+                               this.smokeLatestValue = eventDataMap["value"]
+                               this.smoke = eventDataMap["value"]
+                               this.currentSmokeValue = eventDataMap["value"]
+                               smokeDetectors[0].setValue(eventDataMap["value"], eventDataMap["name"])
+                               sendEvent(eventDataMap)
+                       }
+               } else if (eventDataMap["name"].contains("carbonMonoxide")) {
+                       if (eventDataMap["value"] != smokeDetectors[0].currentCarbonMonoxideValue) {
+                               this.carbonMonoxideLatestValue = eventDataMap["value"]
+                               this.carbonMonoxide = eventDataMap["value"]
+                               this.currentCarbonMonoxideValue = eventDataMap["value"]
+                               smokeDetectors[0].setValue(eventDataMap["value"], eventDataMap["name"])
+                               sendEvent(eventDataMap)
+                       }
+               } else if (eventDataMap["name"].contains("battery")) {
+                       if (eventDataMap["value"].toInteger() != smokeDetectors[0].battery) {
+                               this.battery = eventDataMap["value"].toInteger()
+                               this.batteryLatestValue = eventDataMap["value"].toInteger()
+                               smokeDetectors[0].setValue(eventDataMap["value"], eventDataMap["name"])
+                               sendEvent(eventDataMap)
+                       }
                }
        }
 
@@ -62,6 +90,9 @@ public class SmokeDetectors {
        def find(Closure Input) {
                smokeDetectors.find(Input)
        }
+       def sort(Closure Input) {
+               smokeDetectors.sort(Input)
+       }
        def collect(Closure Input) {
                smokeDetectors.collect(Input)
        }