1 //Create a class for presence sensor
3 import Timer.SimulatedTimer
5 public class MotionSensors {
6 private int deviceNumbers
7 private List motionSensors
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"
19 MotionSensors(Closure sendEvent, int deviceNumbers, boolean init) {
20 this.sendEvent = sendEvent
21 this.deviceNumbers = deviceNumbers
22 this.motionSensors = []
25 this.motion = "inactive"
26 this.currentMotion = "inactive"
27 this.motionLatestValue = "inactive"
29 this.motion = "active"
30 this.currentMotion = "active"
31 this.motionLatestValue = "active"
33 motionSensors.add(new MotionSensor(id, label, displayName, this.motion, this.motionLatestValue))
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)
47 //Methods for closures
48 def count(Closure Input) {
49 motionSensors.count(Input)
54 def each(Closure Input) {
55 motionSensors.each(Input)
57 def find(Closure Input) {
58 motionSensors.find(Input)
60 def sort(Closure Input) {
61 motionSensors.sort(Input)
63 def collect(Closure Input) {
64 motionSensors.collect(Input)
68 def currentValue(String deviceFeature) {
69 motionSensors[0].currentValue(deviceFeature)//It is called if we have only one device
72 def latestValue(String deviceFeature) {
73 motionSensors[0].latestValue(deviceFeature)//It is called if we have only one device
76 def statesSince(String info, Date dateObj) {
77 return motionSensors[0].statesSince(info, dateObj)