1 //Create a class for contact sensor
4 public class Contacting{
5 private int deviceNumbers
9 Contacting(Closure sendEvent, int deviceNumbers) {
10 this.sendEvent = sendEvent
11 this.deviceNumbers = deviceNumbers
13 if (deviceNumbers == 1) {
14 contacts = [new Contacts(sendEvent, 0, "contact0", "closed", "closed")]
15 } else if (deviceNumbers == 2) {
16 contacts = [new Contacts(sendEvent, 0, "contact0", "closed", "closed"), new Contacts(sendEvent, 1, "contact1", "closed", "closed")]
17 } else if (deviceNumbers == 3) {
18 contacts = [new Contacts(sendEvent, 0, "contact0", "closed", "closed"), new Contacts(sendEvent, 1, "contact1", "closed", "closed")
19 ,new Contacts(sendEvent, 2, "contact2", "closed", "closed")]
24 def setValue(LinkedHashMap eventDataMap) {
25 contacts[eventDataMap["deviceId"]].setValue(eventDataMap["value"])
26 sendEvent(eventDataMap)
29 def currentValue(String deviceFeature) {
30 if (deviceNumbers == 1)
31 contacts[0].currentValue(deviceFeature)//It is called if we have only one device
33 contacts*.currentValue(deviceFeature)
36 def latestValue(String deviceFeature) {
37 if (deviceNumbers == 1)
38 contacts[0].latestValue(deviceFeature)//It is called if we have only one device
40 contacts*.latestValue(deviceFeature)