Fixing bug in Mobile Presence class
[smartthings-infrastructure.git] / SmokeDetector / SmokeDetectors.groovy
index 2bbc41d5706704716753b6c2ec91bd7b350050a3..7bc455a076f3cd79bd699e38d6375a931e9dc043 100644 (file)
@@ -1,81 +1,25 @@
 //Create a class for smoke detector
 package SmokeDetector
-import Timer.SimulatedTimer
-
-//JPF's Verify API
-import gov.nasa.jpf.vm.Verify
-
-public class SmokeDetectors {
-       private int deviceNumbers
-       private List smokeDetectors
-       def sendEvent
-
-       //For one device(We cannot have obj.id)-> We should have obj[0].id
-       private String id = "smokeDetectorID0"
-       private String label = "smokeDetector0"
-       private String displayName = "smokeDetector0"
-       private String smoke = "clear"
-       private String currentSmokeValue = "clear"
-       private String smokeLatestValue = "clear"
+import SmartThing.SmartThings
 
+public class SmokeDetectors extends SmartThings {
+       List smokeDetectors = new ArrayList()
                
-       SmokeDetectors(Closure sendEvent, int deviceNumbers) {
-               this.sendEvent = sendEvent              
-               this.deviceNumbers = deviceNumbers
-               this.smokeDetectors = []
-
-               /*def init = Verify.getInt(0,2)
-               if (init == 0) {
-                       this.currentSmokeValue = "clear"
-                       this.smokeLatestValue = "clear"
-               } else if (init == 1) {
-                       this.currentSmokeValue = "detected"
-                       this.smokeLatestValue = "detected"
-               } else {
-                       this.currentSmokeValue = "tested"
-                       this.smokeLatestValue = "tested"                
-               }*/
-               smokeDetectors.add(new SmokeDetector(id, label, displayName, this.currentSmokeValue, this.smokeLatestValue))
-       }
-
-       //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)
-               }
-       }
-
-       //Methods for closures
-       def count(Closure Input) {
-               smokeDetectors.count(Input)
-       }
-       def size() {
-               smokeDetectors.size()
-       }
-       def each(Closure Input) {
-               smokeDetectors.each(Input)
-       }
-       def find(Closure Input) {
-               smokeDetectors.find(Input)
-       }
-       def collect(Closure Input) {
-               smokeDetectors.collect(Input)
-       }
-
-
-       def currentValue(String deviceFeature) {
-               smokeDetectors[0].currentValue(deviceFeature)//It is called if we have only one device
-       }
-
-       def latestValue(String deviceFeature) {
-               smokeDetectors[0].latestValue(deviceFeature)//It is called if we have only one device
-       }
-
-       def getAt(int ix) {
-               smokeDetectors[ix]
+       SmokeDetectors(Closure sendEvent, boolean init) {
+               // Only initialize one time since we only have one device for each capability
+               smokeDetectors = smartThings
+
+               // Initialization
+               String id = "smokeDetectorID0"
+               String label = "smoke"
+               String displayName = "smokeDetector"
+               String smoke
+
+               if (init)
+                       smoke = "clear"
+               else
+                       smoke = "detected"
+
+               smokeDetectors.add(new SmokeDetector(sendEvent, id, label, displayName, smoke))
        }
 }