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
11 private String id = "contactSensorID0"
12 private String label = "contactSensor0"
13 private String displayName = "contactSensor0"
14 private String contactState = "closed"
15 private String latestValue = "closed"
18 ContactSensors(Closure sendEvent, int deviceNumbers) {
19 this.sendEvent = sendEvent
20 this.deviceNumbers = deviceNumbers
23 contacts.add(new ContactSensor(id, label, displayName, this.contactState, this.latestValue))
26 //Methods for closures
27 def count(Closure Input) {
33 def each(Closure Input) {
36 def find(Closure Input) {
39 def collect(Closure Input) {
40 contacts.collect(Input)
44 def setValue(LinkedHashMap eventDataMap) {
45 contacts[0].setValue(eventDataMap["value"])
46 this.latestValue = contacts[0].latestValue
47 this.contactState = contacts[0].contactState
48 sendEvent(eventDataMap)
51 def currentValue(String deviceFeature) {
52 contacts[0].currentValue(deviceFeature)//It is called if we have only one device
55 def latestValue(String deviceFeature) {
56 contacts[0].latestValue(deviceFeature)//It is called if we have only one device