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, boolean init) {
18 this.sendEvent = sendEvent
19 this.deviceNumbers = deviceNumbers
20 this.sleepSensors = []
23 this.sleeping = "sleeping"
25 this.sleeping = "not sleeping"
27 sleepSensors.add(new SleepSensor(id, label, displayName, this.sleeping))
31 def setValue(LinkedHashMap eventDataMap) {
32 if (eventDataMap["value"] != sleepSensors[0].sleeping) {
33 this.sleeping = eventDataMap["value"]
34 sleepSensors[0].setValue(eventDataMap["value"])
35 sendEvent(eventDataMap)
39 //Methods for closures
40 def count(Closure Input) {
41 sleepSensors.count(Input)
46 def each(Closure Input) {
47 sleepSensors.each(Input)
49 def find(Closure Input) {
50 sleepSensors.find(Input)
52 def sort(Closure Input) {
53 sleepSensors.sort(Input)
55 def collect(Closure Input) {
56 sleepSensors.collect(Input)