1 //Create a class for smoke detector
3 import Timer.SimulatedTimer
5 public class SmokeDetector {
8 private String displayName
10 private String currentSmokeValue
11 private String smokeLatestValue
12 private String carbonMonoxide
13 private String currentCarbonMonoxideValue
14 private String carbonMonoxideLatestValue
16 private int batteryLatestValue
18 SmokeDetector(String id, String label, String displayName, String smoke, String smokeLatestValue, String carbonMonoxide, String carbonMonoxideLatestValue, int battery) {
21 this.displayName = displayName
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
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
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()
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") {
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