Changes in classes: new concept for latest value + all types of events generated...
[smartthings-infrastructure.git] / SmokeDetector / SmokeDetector.groovy
1 //Create a class for smoke detector
2 package SmokeDetector
3 import Timer.SimulatedTimer
4
5 public class SmokeDetector {
6         private String id
7         private String label
8         private String displayName
9         private String smoke
10         private String currentSmokeValue
11         private String smokeLatestValue
12         private String carbonMonoxide
13         private String currentCarbonMonoxideValue
14         private String carbonMonoxideLatestValue
15         private int battery
16         private int batteryLatestValue
17
18         SmokeDetector(String id, String label, String displayName, String smoke, String smokeLatestValue, String carbonMonoxide, String carbonMonoxideLatestValue, int battery) {
19                 this.id = id
20                 this.label = label
21                 this.displayName = displayName
22                 this.smoke = smoke
23                 this.currentSmokeValue = smoke
24                 this.smokeLatestValue = smokeLatestValue
25                 this.carbonMonoxide = carbonMonoxide
26                 this.currentCarbonMonoxideValue = currentCarbonMonoxideValue
27                 this.carbonMonoxideLatestValue = carbonMonoxideLatestValue
28                 this.battery = battery
29                 this.batteryLatestValue = battery
30         }
31
32         def setValue(String value, String name) {
33                 if (name.contains("smoke")) {
34                         println("the smoke value of smoke detector with id:$id is triggered to $value!")
35                         this.smokeLatestValue = value
36                         this.smoke = value
37                         this.currentSmokeValue = value
38                 } else if (name.contains("carbonMonoxide")) {
39                         println("the carbonMonoxide value of smoke detector with id:$id is triggered to $value!")
40                         this.carbonMonoxideLatestValue = value
41                         this.carbonMonoxide = value
42                         this.currentCarbonMonoxideValue = value
43                 } else if (name.contains("battery")) {
44                         println("the battery value of smoke detector with id:$id is triggered to $value!")
45                         this.batteryLatestValue = value.toInteger()
46                         this.battery = value.toInteger()
47                 }
48                 
49         }
50
51         
52         def currentValue(String deviceFeature) {
53                 if (deviceFeature == "smoke") {
54                         return currentSmokeValue
55                 } else if (deviceFeature == "carbonMonoxide") {
56                         return currentCarbonMonoxideValue
57                 } else if (deviceFeature == "battery") {
58                         return battery
59                 }
60         }
61
62         def latestValue(String deviceFeature) {
63                 if (deviceFeature == "smoke") {
64                         return smokeLatestValue
65                 } else if (deviceFeature == "carbonMonoxide") {
66                         return carbonMonoxideLatestValue
67                 } else if (deviceFeature == "battery") {
68                         return batteryLatestValue
69                 }
70         }
71 }