A change in location class for sunset/sunrise event + Adding appList for dimmer's...
[smartthings-infrastructure.git] / SleepSensor / SleepSensors.groovy
1 //Create a class for sleep sensor
2 package SleepSensor
3 import Timer.SimulatedTimer
4
5 public class SleepSensors {
6         private int deviceNumbers
7         private List sleepSensors
8         def sendEvent
9
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"
15
16                 
17         SleepSensors(Closure sendEvent, int deviceNumbers, boolean init) {
18                 this.sendEvent = sendEvent              
19                 this.deviceNumbers = deviceNumbers
20                 this.sleepSensors = []
21
22                 if (init) {
23                         this.sleeping = "sleeping"
24                 } else {
25                         this.sleeping = "not sleeping"
26                 }
27                 sleepSensors.add(new SleepSensor(id, label, displayName, this.sleeping))
28         }
29
30         //By Model Checker
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)
36                 }
37         }
38
39         //Methods for closures
40         def count(Closure Input) {
41                 sleepSensors.count(Input)
42         }
43         def size() {
44                 sleepSensors.size()
45         }
46         def each(Closure Input) {
47                 sleepSensors.each(Input)
48         }
49         def find(Closure Input) {
50                 sleepSensors.find(Input)
51         }
52         def sort(Closure Input) {
53                 sleepSensors.sort(Input)
54         }
55         def collect(Closure Input) {
56                 sleepSensors.collect(Input)
57         }
58
59         def getAt(int ix) {
60                 sleepSensors[ix]
61         }
62 }