1 //Create a class for water sensor
3 import Timer.SimulatedTimer
5 public class WaterSensors {
6 private int deviceNumbers
7 private List waterSensors
10 //For one device(We cannot have obj.id)-> We should have obj[0].id
11 private String id = "waterSensorID0"
12 private String label = "waterSensor0"
13 private String displayName = "waterSensor0"
14 private String water = "dry"
17 WaterSensors(Closure sendEvent, int deviceNumbers, boolean init) {
18 this.sendEvent = sendEvent
19 this.deviceNumbers = deviceNumbers
20 this.waterSensors = []
27 waterSensors.add(new WaterSensor(id, label, displayName, this.water))
31 def setValue(LinkedHashMap eventDataMap) {
32 if (eventDataMap["value"] != waterSensors[0].water) {
33 this.water = eventDataMap["value"]
34 waterSensors[0].setValue(eventDataMap["value"])
35 sendEvent(eventDataMap)
39 //Methods for closures
40 def count(Closure Input) {
41 waterSensors.count(Input)
46 def each(Closure Input) {
47 waterSensors.each(Input)
49 def find(Closure Input) {
50 waterSensors.find(Input)
52 def sort(Closure Input) {
53 waterSensors.sort(Input)
55 def collect(Closure Input) {
56 waterSensors.collect(Input)