creating eventsSince for ContactSensor and AeonKeyFobs + commenting runAfter method...
[smartthings-infrastructure.git] / ContactSensor / ContactSensors.groovy
index 489200dbf0a43907d3556cef56f50c528d7a5834..5f5f20e97b9ad97e13bcdfd96493de08f0c53141 100644 (file)
@@ -25,23 +25,6 @@ public class ContactSensors {
                this.deviceNumbers = deviceNumbers
                this.contacts = []
 
-               def initSensor = Verify.getBoolean()
-               if (initSensor) {
-                       this.contactState = "closed"
-                       this.currentContact = "closed"
-                       this.latestValue = "closed"
-               } else {
-                       this.contactState = "open"
-                       this.currentContact = "open"
-                       this.latestValue = "open"
-               }
-
-               def initAlarm = Verify.getBoolean()
-               if (initAlarm) {
-                       this.alarmState = "armed"
-               } else {
-                       this.alarmState = "not armed"
-               }
                contacts.add(new ContactSensor(id, label, displayName, this.contactState, this.currentContact, this.alarmState, this.latestValue))
        }
 
@@ -58,6 +41,9 @@ public class ContactSensors {
        def find(Closure Input) {
                contacts.find(Input)
        }
+       def sort(Closure Input) {
+               contacts.sort(Input)
+       }
        def collect(Closure Input) {
                contacts.collect(Input)
        }
@@ -65,28 +51,36 @@ public class ContactSensors {
        //By Model Checker
        def setValue(LinkedHashMap eventDataMap) {
                if (eventDataMap["value"] != contacts[0].contactState) {
+                       this.latestValue = eventDataMap["value"]
+                       this.contactState = eventDataMap["value"]
+                       this.currentContact = eventDataMap["value"]
                        contacts[0].setValue(eventDataMap["value"])
-                       this.latestValue = contacts[0].latestValue
-                       this.contactState = contacts[0].contactState
-                       this.currentContact = contacts[0].contactState
                        sendEvent(eventDataMap)
                }
        }
 
+       def eventsSince(Date dateObj) {
+               return contacts[0].eventsSince()
+       }
+
        def on() {
-               contacts[0].on()
                this.alarmState = "armed"
+               contacts[0].on()
        }
 
        def off() {
-               contacts[0].off()
                this.alarmState = "not armed"
+               contacts[0].off()
        }
 
        def currentValue(String deviceFeature) {
                contacts[0].currentValue(deviceFeature)//It is called if we have only one device
        }
 
+       def currentState(String deviceFeature) {
+               contacts[0].currentState(deviceFeature)//It is called if we have only one device
+       }
+
        def latestValue(String deviceFeature) {
                contacts[0].latestValue(deviceFeature)//It is called if we have only one device
        }