1 //Create a class for smoke detector
3 import Timer.SimulatedTimer
5 public class SmokeDetectors {
6 private int deviceNumbers
7 private List smokeDetectors
10 //For one device(We cannot have obj.id)-> We should have obj[0].id
11 private String id = "smokeDetectorID0"
12 private String label = "smokeDetector0"
13 private String displayName = "smokeDetector0"
14 private String smoke = "clear"
15 private String currentSmokeValue = "clear"
16 private String smokeLatestValue = "clear"
19 SmokeDetectors(Closure sendEvent, int deviceNumbers) {
20 this.sendEvent = sendEvent
21 this.deviceNumbers = deviceNumbers
22 this.smokeDetectors = []
24 smokeDetectors.add(new SmokeDetector(id, label, displayName, this.currentSmokeValue, this.smokeLatestValue))
28 def setValue(LinkedHashMap eventDataMap) {
29 if (eventDataMap["value"] != smokeDetectors[0].currentSmokeValue) {
30 smokeDetectors[0].setValue(eventDataMap["value"])
31 this.smokeLatestValue = smokeDetectors[0].smokeLatestValue
32 this.smoke = smokeDetectors[0].currentSmokeValue
33 this.currentSmokeValue = smokeDetectors[0].currentSmokeValue
34 sendEvent(eventDataMap)
38 //Methods for closures
39 def count(Closure Input) {
40 smokeDetectors.count(Input)
45 def each(Closure Input) {
46 smokeDetectors.each(Input)
48 def find(Closure Input) {
49 smokeDetectors.find(Input)
51 def collect(Closure Input) {
52 smokeDetectors.collect(Input)
56 def currentValue(String deviceFeature) {
57 smokeDetectors[0].currentValue(deviceFeature)//It is called if we have only one device
60 def latestValue(String deviceFeature) {
61 smokeDetectors[0].latestValue(deviceFeature)//It is called if we have only one device