Changes in classes: new concept for latest value + all types of events generated...
[smartthings-infrastructure.git] / CarbonMonoxideDetector / CarbonMonoxideDetector.groovy
1 //Create a class for carbon monoxide detector
2 package CarbonMonoxideDetector
3 import Timer.SimulatedTimer
4
5 public class CarbonMonoxideDetector {
6         private String id
7         private String label
8         private String displayName
9         private String carbonMonoxide
10         private String currentCarbonMonoxideValue
11         private String carbonMonoxideLatestValue
12
13         CarbonMonoxideDetector(String id, String label, String displayName, String carbonMonoxide, String carbonMonoxideLatestValue) {
14                 this.id = id
15                 this.label = label
16                 this.displayName = displayName
17                 this.carbonMonoxide = carbonMonoxide
18                 this.currentCarbonMonoxideValue = carbonMonoxide
19                 this.carbonMonoxideLatestValue = carbonMonoxideLatestValue
20         }
21
22         def setValue(String value) {
23                 println("the carbon monoxide detector with id:$id is triggered to $value!")
24                 this.carbonMonoxideLatestValue = value
25                 this.carbonMonoxide = value
26                 this.currentCarbonMonoxideValue = value
27         }
28
29         
30         def currentValue(String deviceFeature) {
31                 if (deviceFeature == "carbonMonoxide") {
32                         return currentCarbonMonoxideValue
33                 }
34         }
35
36         def latestValue(String deviceFeature) {
37                 if (deviceFeature == "carbonMonoxide") {
38                         return carbonMonoxideLatestValue
39                 }
40         }
41 }