1 //Create a class for contact sensor
3 import Timer.SimulatedTimer
5 public class ContactSensors {
6 private int deviceNumbers
10 //For one device(We cannot have obj.id)-> We should have obj[0].id
12 private String label = "contactSensor"
13 private String displayName = "contactSensor"
14 private String contactState = "closed"
15 private String contactLatestValue = "closed"
18 ContactSensors(Closure sendEvent, int deviceNumbers) {
19 this.sendEvent = sendEvent
20 this.deviceNumbers = deviceNumbers
23 for (int i = 0;i < deviceNumbers;i++) {
24 contacts.add(new ContactSensor(i+10, label+i.toString(), displayName+i.toString(), this.contactState, this.contactLatestValue))
28 //Methods for closures
29 def count(Closure Input) {
35 def each(Closure Input) {
40 def setValue(LinkedHashMap eventDataMap) {
41 contacts[eventDataMap["deviceId"]].setValue(eventDataMap["value"])
42 if (deviceNumbers == 1)
43 this.contactLatestValue = contacts[eventDataMap["deviceId"]].contactLatestValue
44 this.contactState = contacts[eventDataMap["deviceId"]].contactState
45 sendEvent(eventDataMap)
48 def currentValue(String deviceFeature) {
49 if (deviceNumbers == 1)
50 contacts[0].currentValue(deviceFeature)//It is called if we have only one device
52 contacts*.currentValue(deviceFeature)
55 def latestValue(String deviceFeature) {
56 if (deviceNumbers == 1)
57 contacts[0].latestValue(deviceFeature)//It is called if we have only one device
59 contacts*.latestValue(deviceFeature)