Merge branch 'master' of ssh://plrg.eecs.uci.edu/home/git/smartthings-infrastructure
[smartthings-infrastructure.git] / SmokeDetector / SmokeDetector.groovy
index 3182cc3a62442c831e2e8fa7e8a8886cda90a078..07b6764d1e43e6859569900cde1fc955a41e6719 100644 (file)
@@ -9,33 +9,63 @@ public class SmokeDetector {
        private String smoke
        private String currentSmokeValue
        private String smokeLatestValue
+       private String carbonMonoxide
+       private String currentCarbonMonoxideValue
+       private String carbonMonoxideLatestValue
+       private int battery
+       private int batteryLatestValue
 
-       SmokeDetector(String id, String label, String displayName, String smoke, String smokeLatestValue) {
+       SmokeDetector(String id, String label, String displayName, String smoke, String smokeLatestValue, String carbonMonoxide, String carbonMonoxideLatestValue, int battery) {
                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) {
-               this.smokeLatestValue = smoke
-               println("the smoke detector with id:$id is triggered to $value!")
-               this.smoke = value
-               this.currentSmokeValue = value
+       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
                }
        }
 }