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) {
20 this.sendEvent = sendEvent
21 this.deviceNumbers = deviceNumbers
22 this.motionSensors = []
24 motionSensors.add(new MotionSensor(id, label, displayName, this.motion, this.motionLatestValue))
28 def setValue(LinkedHashMap eventDataMap) {
29 if (eventDataMap["value"] != motionSensors[0].motion) {
30 motionSensors[0].setValue(eventDataMap["value"])
31 this.motionLatestValue = motionSensors[0].motionLatestValue
32 this.motion = motionSensors[0].motion
33 this.currentMotion = motionSensors[0].motion
34 sendEvent(eventDataMap)
38 //Methods for closures
39 def count(Closure Input) {
40 motionSensors.count(Input)
45 def each(Closure Input) {
46 motionSensors.each(Input)
48 def find(Closure Input) {
49 motionSensors.find(Input)
51 def collect(Closure Input) {
52 motionSensors.collect(Input)
56 def currentValue(String deviceFeature) {
57 motionSensors[0].currentValue(deviceFeature)//It is called if we have only one device
60 def latestValue(String deviceFeature) {
61 motionSensors[0].latestValue(deviceFeature)//It is called if we have only one device
64 def statesSince(String info, Date dateObj) {
65 return motionSensors[0].statesSince(info, dateObj)