Infrastruction modification
[smartthings-infrastructure.git] / CarbonMonoxideDetector / CarbonMonoxideDetector.groovy
index 213d1531d3ec79c7353f6d893d55f0c885dfe859..65f1ce0d99bf1209a2988e8888753d287fb1b6fc 100644 (file)
@@ -1,41 +1,35 @@
 //Create a class for carbon monoxide detector
 package CarbonMonoxideDetector
 //Create a class for carbon monoxide detector
 package CarbonMonoxideDetector
-import Timer.SimulatedTimer
+import SmartThing.SmartThing
 
 
-public class CarbonMonoxideDetector {
-       private String id
-       private String label
-       private String displayName
-       private String carbonMonoxide
-       private String currentCarbonMonoxideValue
-       private String carbonMonoxideLatestValue
+public class CarbonMonoxideDetector 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 currentCarbonMonoxideValue = new StringBuilder()
+       // Maps from features to values
+       HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
 
 
-       CarbonMonoxideDetector(String id, String label, String displayName, String carbonMonoxide, String carbonMonoxideLatestValue) {
+       CarbonMonoxideDetector(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentCarbonMonoxideValue) {
+               deviceValuesMap = deviceValueSmartThing
+               idSmartThing = id
+               labelSmartThing = label
+               displayNameSmartThing = displayName
+               sendEventSmartThings = sendEvent
+
+               // Initialization
                this.id = id
                this.label = label
                this.displayName = displayName
                this.id = id
                this.label = label
                this.displayName = displayName
-               this.carbonMonoxide = carbonMonoxide
-               this.currentCarbonMonoxideValue = carbonMonoxide
-               this.carbonMonoxideLatestValue = carbonMonoxideLatestValue
-       }
-
-       def setValue(String value) {
-               println("the carbon monoxide detector with id:$id is triggered to $value!")
-               this.carbonMonoxideLatestValue = value
-               this.carbonMonoxide = value
-               this.currentCarbonMonoxideValue = value
-       }
+               this.currentCarbonMonoxideValue = currentCarbonMonoxideValue
 
 
-       
-       def currentValue(String deviceFeature) {
-               if (deviceFeature == "carbonMonoxide") {
-                       return currentCarbonMonoxideValue
-               }
+               deviceValuesMap.put("carbonMonoxide", currentCarbonMonoxideValue)
        }
 
        }
 
-       def latestValue(String deviceFeature) {
-               if (deviceFeature == "carbonMonoxide") {
-                       return carbonMonoxideLatestValue
-               }
+       // Methods to return values
+       def getCurrentCarbonMonoxideValue() {
+               return currentCarbonMonoxideValue.toString()
        }
 }
        }
 }