1 //Create a class for carbon monoxide detector
2 package CarbonMonoxideDetector
3 import Timer.SimulatedTimer
5 public class CarbonMonoxideDetectors {
6 private int deviceNumbers
7 private List carbonMonoxideDetectors
10 //For one device(We cannot have obj.id)-> We should have obj[0].id
11 private String id = "carbonMonoxideDetectorID0"
12 private String label = "carbonMonoxideDetector0"
13 private String displayName = "carbonMonoxideDetector0"
14 private String carbonMonoxide = "clear"
15 private String currentCarbonMonoxideValue = "clear"
16 private String carbonMonoxideLatestValue = "clear"
19 CarbonMonoxideDetectors(Closure sendEvent, int deviceNumbers, boolean init) {
20 this.sendEvent = sendEvent
21 this.deviceNumbers = deviceNumbers
22 this.carbonMonoxideDetectors = []
25 this.carbonMonoxide = "clear"
26 this.currentCarbonMonoxideValue = "clear"
27 this.carbonMonoxideLatestValue = "clear"
28 } else if (init == 1) {
29 this.carbonMonoxide = "detected"
30 this.currentCarbonMonoxideValue = "detected"
31 this.carbonMonoxideLatestValue = "detected"
33 carbonMonoxideDetectors.add(new CarbonMonoxideDetector(id, label, displayName, this.currentCarbonMonoxideValue, this.carbonMonoxideLatestValue))
37 def setValue(LinkedHashMap eventDataMap) {
38 if (eventDataMap["value"] != carbonMonoxideDetectors[0].currentCarbonMonoxideValue) {
39 this.carbonMonoxideLatestValue = eventDataMap["value"]
40 this.carbonMonoxide = eventDataMap["value"]
41 this.currentCarbonMonoxideValue = eventDataMap["value"]
42 carbonMonoxideDetectors[0].setValue(eventDataMap["value"])
43 sendEvent(eventDataMap)
47 //Methods for closures
48 def count(Closure Input) {
49 carbonMonoxideDetectors.count(Input)
52 carbonMonoxideDetectors.size()
54 def each(Closure Input) {
55 carbonMonoxideDetectors.each(Input)
57 def find(Closure Input) {
58 carbonMonoxideDetectors.find(Input)
60 def sort(Closure Input) {
61 carbonMonoxideDetectors.sort(Input)
63 def collect(Closure Input) {
64 carbonMonoxideDetectors.collect(Input)
68 def currentValue(String deviceFeature) {
69 carbonMonoxideDetectors[0].currentValue(deviceFeature)//It is called if we have only one device
72 def latestValue(String deviceFeature) {
73 carbonMonoxideDetectors[0].latestValue(deviceFeature)//It is called if we have only one device
77 carbonMonoxideDetectors[ix]