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) {
21 this.sendEvent = sendEvent
22 this.deviceNumbers = deviceNumbers
25 contacts.add(new ContactSensor(id, label, displayName, this.contactState, this.currentContact, this.alarmState, this.latestValue))
28 //Methods for closures
29 def count(Closure Input) {
35 def each(Closure Input) {
38 def find(Closure Input) {
41 def collect(Closure Input) {
42 contacts.collect(Input)
46 def setValue(LinkedHashMap eventDataMap) {
47 if (eventDataMap["value"] != contacts[0].contactState) {
48 contacts[0].setValue(eventDataMap["value"])
49 this.latestValue = contacts[0].latestValue
50 this.contactState = contacts[0].contactState
51 this.currentContact = contacts[0].contactState
52 sendEvent(eventDataMap)
58 this.alarmState = "armed"
63 this.alarmState = "not armed"
66 def currentValue(String deviceFeature) {
67 contacts[0].currentValue(deviceFeature)//It is called if we have only one device
70 def latestValue(String deviceFeature) {
71 contacts[0].latestValue(deviceFeature)//It is called if we have only one device