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