Fixing bug in Mobile Presence class
[smartthings-infrastructure.git] / SmokeDetector / SmokeDetector.groovy
index 3182cc3a62442c831e2e8fa7e8a8886cda90a078..b9ebeced6cde48e402b0f147a3e3d186ae5c8d71 100644 (file)
@@ -1,41 +1,27 @@
 //Create a class for smoke detector
 package SmokeDetector
-import Timer.SimulatedTimer
+import SmartThing.SmartThing
 
-public class SmokeDetector {
-       private String id
-       private String label
-       private String displayName
-       private String smoke
-       private String currentSmokeValue
-       private String smokeLatestValue
+public class SmokeDetector extends SmartThing {
+       // id, label, and display name of the device
+       String id
+       String label
+       String displayName
+       // Maps from features to values
+       HashMap<String, String> deviceValuesMap = new HashMap<String, String>()
 
-       SmokeDetector(String id, String label, String displayName, String smoke, String smokeLatestValue) {
+       SmokeDetector(Closure sendEvent, String id, String label, String displayName, String currentSmoke) {
+               deviceValueSmartThing = deviceValuesMap
+               idSmartThing = id
+               labelSmartThing = label
+               displayNameSmartThing = displayName
+               sendEventSmartThings = sendEvent
+
+               // Initialization
                this.id = id
                this.label = label
                this.displayName = displayName
-               this.smoke = smoke
-               this.currentSmokeValue = smoke
-               this.smokeLatestValue = smokeLatestValue
-       }
-
-       def setValue(String value) {
-               this.smokeLatestValue = smoke
-               println("the smoke detector with id:$id is triggered to $value!")
-               this.smoke = value
-               this.currentSmokeValue = value
-       }
-
-       
-       def currentValue(String deviceFeature) {
-               if (deviceFeature == "smoke") {
-                       return currentSmokeValue
-               }
-       }
 
-       def latestValue(String deviceFeature) {
-               if (deviceFeature == "smoke") {
-                       return smokeLatestValue
-               }
+               deviceValuesMap.put("smoke", currentSmoke)
        }
 }