Solving conflicts
[smartthings-infrastructure.git] / MotionSensor / MotionSensors.groovy
1 //Create a class for presence sensor
2 package MotionSensor
3 import Timer.SimulatedTimer
4
5 public class MotionSensors {
6         private int deviceNumbers
7         private List motionSensors
8         def sendEvent
9
10         //For one device(We cannot have obj.id)-> We should have obj[0].id
11         private String id = "motionSensorID0"
12         private String label = "motionSensor0"
13         private String displayName = "motionSensor0"
14         private String motion = "inactive"
15         private String currentMotion = "inactive"
16         private String motionLatestValue = "inactive"
17
18                 
19         MotionSensors(Closure sendEvent, int deviceNumbers, boolean init) {
20                 this.sendEvent = sendEvent              
21                 this.deviceNumbers = deviceNumbers
22                 this.motionSensors = []
23
24                 if (init) {
25                         this.motion = "inactive"
26                         this.currentMotion = "inactive"
27                         this.motionLatestValue = "inactive"
28                 } else {
29                         this.motion = "active"
30                         this.currentMotion = "active"
31                         this.motionLatestValue = "active"
32                 }
33                 motionSensors.add(new MotionSensor(id, label, displayName, this.motion, this.motionLatestValue))
34         }
35
36         //By Model Checker
37         def setValue(LinkedHashMap eventDataMap) {
38                 if (eventDataMap["value"] != motionSensors[0].motion) {
39                         this.motionLatestValue = eventDataMap["value"]
40                         this.motion = eventDataMap["value"]
41                         this.currentMotion = eventDataMap["value"]
42                         motionSensors[0].setValue(eventDataMap["value"])
43                         sendEvent(eventDataMap)
44                 }
45         }
46
47         //Methods for closures
48         def count(Closure Input) {
49                 motionSensors.count(Input)
50         }
51         def size() {
52                 motionSensors.size()
53         }
54         def each(Closure Input) {
55                 motionSensors.each(Input)
56         }
57         def find(Closure Input) {
58                 motionSensors.find(Input)
59         }
60         def sort(Closure Input) {
61                 motionSensors.sort(Input)
62         }
63         def collect(Closure Input) {
64                 motionSensors.collect(Input)
65         }
66
67
68         def currentValue(String deviceFeature) {
69                 motionSensors[0].currentValue(deviceFeature)//It is called if we have only one device
70         }
71
72         def latestValue(String deviceFeature) {
73                 motionSensors[0].latestValue(deviceFeature)//It is called if we have only one device
74         }
75
76         def statesSince(String info, Date dateObj) {
77                 return motionSensors[0].statesSince(info, dateObj)
78         }
79
80         def getAt(int ix) {
81                 motionSensors[ix]
82         }
83 }