Fixing bug in Mobile Presence class
[smartthings-infrastructure.git] / SmokeDetector / SmokeDetector.groovy
index 07b6764d1e43e6859569900cde1fc955a41e6719..b9ebeced6cde48e402b0f147a3e3d186ae5c8d71 100644 (file)
@@ -1,71 +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
-       private String carbonMonoxide
-       private String currentCarbonMonoxideValue
-       private String carbonMonoxideLatestValue
-       private int battery
-       private int batteryLatestValue
+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, String carbonMonoxide, String carbonMonoxideLatestValue, int battery) {
+       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
-               this.carbonMonoxide = carbonMonoxide
-               this.currentCarbonMonoxideValue = currentCarbonMonoxideValue
-               this.carbonMonoxideLatestValue = carbonMonoxideLatestValue
-               this.battery = battery
-               this.batteryLatestValue = battery
-       }
-
-       def setValue(String value, String name) {
-               if (name.contains("smoke")) {
-                       println("the smoke value of smoke detector with id:$id is triggered to $value!")
-                       this.smokeLatestValue = value
-                       this.smoke = value
-                       this.currentSmokeValue = value
-               } else if (name.contains("carbonMonoxide")) {
-                       println("the carbonMonoxide value of smoke detector with id:$id is triggered to $value!")
-                       this.carbonMonoxideLatestValue = value
-                       this.carbonMonoxide = value
-                       this.currentCarbonMonoxideValue = value
-               } else if (name.contains("battery")) {
-                       println("the battery value of smoke detector with id:$id is triggered to $value!")
-                       this.batteryLatestValue = value.toInteger()
-                       this.battery = value.toInteger()
-               }
-               
-       }
-
-       
-       def currentValue(String deviceFeature) {
-               if (deviceFeature == "smoke") {
-                       return currentSmokeValue
-               } else if (deviceFeature == "carbonMonoxide") {
-                       return currentCarbonMonoxideValue
-               } else if (deviceFeature == "battery") {
-                       return battery
-               }
-       }
 
-       def latestValue(String deviceFeature) {
-               if (deviceFeature == "smoke") {
-                       return smokeLatestValue
-               } else if (deviceFeature == "carbonMonoxide") {
-                       return carbonMonoxideLatestValue
-               } else if (deviceFeature == "battery") {
-                       return batteryLatestValue
-               }
+               deviceValuesMap.put("smoke", currentSmoke)
        }
 }