1 //Create a class for contact sensor
3 import Timer.SimulatedTimer
5 public class Contacting {
6 private int deviceNumbers
10 //For one device(We cannot have obj.id)-> We should have obj[0].id
12 private String displayName = "contact0"
13 private String contactState = "closed"
14 private String contactLatestValue = "closed"
17 Contacting(Closure sendEvent, int deviceNumbers) {
18 this.sendEvent = sendEvent
19 this.deviceNumbers = deviceNumbers
23 if (deviceNumbers == 1) {
24 contacts = [new Contacts(this.id, this.displayName, this.contactState, this.contactLatestValue)]
25 } else if (deviceNumbers == 2) {
26 contacts = [new Contacts(0, "contact0", "closed", "closed"), new Contacts(1, "contact1", "closed", "closed")]
27 } else if (deviceNumbers == 3) {
28 contacts = [new Contacts(0, "contact0", "closed", "closed"), new Contacts(1, "contact1", "closed", "closed")
29 ,new Contacts(2, "contact2", "closed", "closed")]
34 def setValue(LinkedHashMap eventDataMap) {
35 contacts[eventDataMap["deviceId"]].setValue(eventDataMap["value"])
36 if (deviceNumbers == 1)
37 this.contactLatestValue = contacts[eventDataMap["deviceId"]].contactLatestValue
38 this.contactState = contacts[eventDataMap["deviceId"]].contactState
39 sendEvent(eventDataMap)
42 def currentValue(String deviceFeature) {
43 if (deviceNumbers == 1)
44 contacts[0].currentValue(deviceFeature)//It is called if we have only one device
46 contacts*.currentValue(deviceFeature)
49 def latestValue(String deviceFeature) {
50 if (deviceNumbers == 1)
51 contacts[0].latestValue(deviceFeature)//It is called if we have only one device
53 contacts*.latestValue(deviceFeature)