1 //Create a class for contact sensor
4 public class Contacting{
5 private int deviceNumbers
11 Contacting(Closure sendEvent, int deviceNumbers) {
12 this.sendEvent = sendEvent
13 this.deviceNumbers = deviceNumbers
16 for (int i = 0;i < deviceNumbers;i++) {
17 contacts.add(new Contacts(id, "contact"+id.toString(), "closed", "closed"))//By default closed
23 def setValue(LinkedHashMap eventDataMap) {
24 contacts[eventDataMap["deviceId"]].setValue(eventDataMap["value"])
25 sendEvent(eventDataMap)
28 def currentValue(String deviceFeature) {
29 if (deviceNumbers == 1)
30 contacts[0].currentValue(deviceFeature)//It is called if we have only one device
32 contacts*.currentValue(deviceFeature)
35 def latestValue(String deviceFeature) {
36 if (deviceNumbers == 1)
37 contacts[0].latestValue(deviceFeature)//It is called if we have only one device
39 contacts*.latestValue(deviceFeature)