1 //Create a class for presence sensor
3 import Timer.SimulatedTimer
5 public class PresenceSensors {
6 private int deviceNumbers
7 private List presenceSensors
10 //For one device(We cannot have obj.id)-> We should have obj[0].id
11 private String id = "presenceSensorID0"
12 private String label = "presenceSensor0"
13 private String displayName = "presenceSensor0"
14 private String presence = "not present"
15 private String currentPresence = "not present"
16 private String presenceLatestValue = "not present"
19 PresenceSensors(Closure sendEvent, int deviceNumbers, boolean init) {
20 this.sendEvent = sendEvent
21 this.deviceNumbers = deviceNumbers
22 this.presenceSensors = []
25 this.presence = "not present"
26 this.currentPresence = "not present"
27 this.presenceLatestValue = "not present"
29 this.presence = "present"
30 this.currentPresence = "present"
31 this.presenceLatestValue = "present"
33 presenceSensors.add(new PresenceSensor(id, label, displayName, this.presence, this.presenceLatestValue))
37 def setValue(LinkedHashMap eventDataMap) {
38 if (eventDataMap["value"] != presenceSensors[0].presence) {
39 this.presenceLatestValue = eventDataMap["value"]
40 this.presence = eventDataMap["value"]
41 this.currentPresence = eventDataMap["value"]
42 presenceSensors[0].setValue(eventDataMap["value"])
43 sendEvent(eventDataMap)
47 //Methods for closures
48 def count(Closure Input) {
49 presenceSensors.count(Input)
52 presenceSensors.size()
54 def each(Closure Input) {
55 presenceSensors.each(Input)
57 def find(Closure Input) {
58 presenceSensors.find(Input)
60 def sort(Closure Input) {
61 presenceSensors.sort(Input)
63 def collect(Closure Input) {
64 presenceSensors.collect(Input)
67 def currentState(String deviceFeature) {
68 presenceSensors[0].currentState(deviceFeature)
71 def currentValue(String deviceFeature) {
72 presenceSensors[0].currentValue(deviceFeature)//It is called if we have only one device
75 def latestValue(String deviceFeature) {
76 presenceSensors[0].latestValue(deviceFeature)//It is called if we have only one device
79 def statesSince(String info, Date dateObj) {
80 return presenceSensors[0].statesSince()
83 def eventsSince(Date dateObj) {
84 return presenceSensors[0].statesSince()