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 currentContact = "closed"
16 private String latestValue = "closed"
17 private String alarmState = "armed"
20 ContactSensors(Closure sendEvent, int deviceNumbers, boolean init) {
21 this.sendEvent = sendEvent
22 this.deviceNumbers = deviceNumbers
26 this.contactState = "closed"
27 this.currentContact = "closed"
28 this.latestValue = "closed"
29 this.alarmState = "armed"
31 this.contactState = "open"
32 this.currentContact = "open"
33 this.latestValue = "open"
34 this.alarmState = "not armed"
37 contacts.add(new ContactSensor(id, label, displayName, this.contactState, this.currentContact, this.alarmState, this.latestValue))
40 //Methods for closures
41 def count(Closure Input) {
47 def each(Closure Input) {
50 def find(Closure Input) {
53 def sort(Closure Input) {
56 def collect(Closure Input) {
57 contacts.collect(Input)
61 def setValue(LinkedHashMap eventDataMap) {
62 if (eventDataMap["value"] != contacts[0].contactState) {
63 this.latestValue = eventDataMap["value"]
64 this.contactState = eventDataMap["value"]
65 this.currentContact = eventDataMap["value"]
66 contacts[0].setValue(eventDataMap["value"])
67 sendEvent(eventDataMap)
71 def eventsSince(Date dateObj) {
72 return contacts[0].eventsSince()
76 this.alarmState = "armed"
81 this.alarmState = "not armed"
85 def currentValue(String deviceFeature) {
86 contacts[0].currentValue(deviceFeature)//It is called if we have only one device
89 def currentState(String deviceFeature) {
90 contacts[0].currentState(deviceFeature)//It is called if we have only one device
93 def latestValue(String deviceFeature) {
94 contacts[0].latestValue(deviceFeature)//It is called if we have only one device