Fixing a bug in ContactSensor.
[smartthings-infrastructure.git] / ContactSensor / ContactSensor.groovy
index d13993ae3231095369a8a0fdabe74bba220ae7eb..141faf2b7ef3ec33f3af12f7dc1de4c13a04b31a 100644 (file)
@@ -10,6 +10,8 @@ public class ContactSensor {
        private String currentContact   
        private String latestValue
        private String alarmState
+       private List events = []
+       private List timeOfEvents = []
        
 
        ContactSensor(String id, String label, String displayName, String contactState, String currentContact, String alarmState, String latestValue) {
@@ -23,11 +25,23 @@ public class ContactSensor {
        }
 
        def setValue(String value) {
-               this.latestValue = contactState
                println("the contact sensor with id:$id is triggered to $value!")
                this.contactState = value
                this.currentContact = value
+               this.latestValue = value
+               //this.events.add(eventDataMap)
+               //this.timeOfEvents.add(System.currentTimeMillis())
        }
+
+       /*def eventsSince(Date dateObj) {
+               def List happenedEvents = []
+               def sinceThen = dateObj.time
+               for (int i = 0;i < timeOfEvents.size();i++) {
+                       if (timeOfEvents[i]>=sinceThen)
+                               happenedEvents.add(events[i])
+               }
+               return happenedEvents
+       }*/
        
        def on() {
                println("the contact sensor with id:$id is armed!")
@@ -45,6 +59,12 @@ public class ContactSensor {
                }
        }
 
+       def currentState(String deviceFeature) {
+               if (deviceFeature == "contact") {
+                       return contactState
+               }
+       }
+
        def latestValue(String deviceFeature) {
                if (deviceFeature == "contact") {
                        return latestValue