1 //Create a class for carbon monoxide detector
2 package CarbonMonoxideDetector
3 import Timer.SimulatedTimer
5 public class CarbonMonoxideDetector {
8 private String displayName
9 private String carbonMonoxide
10 private String currentCarbonMonoxideValue
11 private String carbonMonoxideLatestValue
13 CarbonMonoxideDetector(String id, String label, String displayName, String carbonMonoxide, String carbonMonoxideLatestValue) {
16 this.displayName = displayName
17 this.carbonMonoxide = carbonMonoxide
18 this.currentCarbonMonoxideValue = carbonMonoxide
19 this.carbonMonoxideLatestValue = carbonMonoxideLatestValue
22 def setValue(String value) {
23 this.carbonMonoxideLatestValue = carbonMonoxide
24 println("the carbon monoxide detector with id:$id is triggered to $value!")
25 this.carbonMonoxide = value
26 this.currentCarbonMonoxideValue = value
30 def currentValue(String deviceFeature) {
31 if (deviceFeature == "carbonMonoxide") {
32 return currentCarbonMonoxideValue
36 def latestValue(String deviceFeature) {
37 if (deviceFeature == "carbonMonoxide") {
38 return carbonMonoxideLatestValue