Changes in classes: new concept for latest value + all types of events generated...
[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) {
18                 this.sendEvent = sendEvent              
19                 this.deviceNumbers = deviceNumbers
20                 this.sleepSensors = []
21
22                 sleepSensors.add(new SleepSensor(id, label, displayName, this.sleeping))
23         }
24
25         //By Model Checker
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)
31                 }
32         }
33
34         //Methods for closures
35         def count(Closure Input) {
36                 sleepSensors.count(Input)
37         }
38         def size() {
39                 sleepSensors.size()
40         }
41         def each(Closure Input) {
42                 sleepSensors.each(Input)
43         }
44         def find(Closure Input) {
45                 sleepSensors.find(Input)
46         }
47         def sort(Closure Input) {
48                 sleepSensors.sort(Input)
49         }
50         def collect(Closure Input) {
51                 sleepSensors.collect(Input)
52         }
53
54         def getAt(int ix) {
55                 sleepSensors[ix]
56         }
57 }