1 //Create a class for sleep sensor
3 import Timer.SimulatedTimer
5 public class SleepSensors {
6 private int deviceNumbers
7 private List sleepSensors
10 //For one device(We cannot have obj.id)-> We should have obj[0].id
11 private String id = "sleepSensorID0"
12 private String label = "sleepSensor0"
13 private String displayName = "sleepSensor0"
14 private String sleeping = "sleeping"
17 SleepSensors(Closure sendEvent, int deviceNumbers) {
18 this.sendEvent = sendEvent
19 this.deviceNumbers = deviceNumbers
20 this.sleepSensors = []
22 sleepSensors.add(new SleepSensor(id, label, displayName, this.sleeping))
26 def setValue(LinkedHashMap eventDataMap) {
27 if (eventDataMap["value"] != sleepSensors[0].sleeping) {
28 this.sleeping = eventDataMap["value"]
29 sleepSensors[0].setValue(eventDataMap["value"])
30 sendEvent(eventDataMap)
34 //Methods for closures
35 def count(Closure Input) {
36 sleepSensors.count(Input)
41 def each(Closure Input) {
42 sleepSensors.each(Input)
44 def find(Closure Input) {
45 sleepSensors.find(Input)
47 def sort(Closure Input) {
48 sleepSensors.sort(Input)
50 def collect(Closure Input) {
51 sleepSensors.collect(Input)