Infrastruction modification
[smartthings-infrastructure.git] / SmokeDetector / SmokeDetector.groovy
index 07b6764d1e43e6859569900cde1fc955a41e6719..9eb9e8a28b613f2b8b854fb240f002e45be50941 100644 (file)
@@ -1,71 +1,35 @@
 //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
+       StringBuilder id = new StringBuilder()
+       StringBuilder label = new StringBuilder()
+       StringBuilder displayName = new StringBuilder()
+       // Features with string values
+       StringBuilder currentSmoke = new StringBuilder()
+       // Maps from features to values
+       HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
 
-       SmokeDetector(String id, String label, String displayName, String smoke, String smokeLatestValue, String carbonMonoxide, String carbonMonoxideLatestValue, int battery) {
+       SmokeDetector(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentSmoke) {
+               deviceValuesMap = deviceValueSmartThing
+               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()
-               }
-               
-       }
+               this.currentSmoke = currentSmoke
 
-       
-       def currentValue(String deviceFeature) {
-               if (deviceFeature == "smoke") {
-                       return currentSmokeValue
-               } else if (deviceFeature == "carbonMonoxide") {
-                       return currentCarbonMonoxideValue
-               } else if (deviceFeature == "battery") {
-                       return battery
-               }
+               deviceValuesMap.put("smoke", currentSmoke)
        }
 
-       def latestValue(String deviceFeature) {
-               if (deviceFeature == "smoke") {
-                       return smokeLatestValue
-               } else if (deviceFeature == "carbonMonoxide") {
-                       return carbonMonoxideLatestValue
-               } else if (deviceFeature == "battery") {
-                       return batteryLatestValue
-               }
+       // Methods to return values
+       def getCurrentSmoke() {
+               return currentSmoke.toString()
        }
 }