creating eventsSince for ContactSensor and AeonKeyFobs + commenting runAfter method...
[smartthings-infrastructure.git] / ContactSensor / ContactSensors.groovy
index 10c4aa61aed7270292d1c03dc77ba2a18cf80a23..5f5f20e97b9ad97e13bcdfd96493de08f0c53141 100644 (file)
@@ -2,6 +2,9 @@
 package ContactSensor
 import Timer.SimulatedTimer
 
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
 public class ContactSensors {
        private int deviceNumbers
        private List contacts
@@ -12,7 +15,9 @@ public class ContactSensors {
        private String label = "contactSensor0"
        private String displayName = "contactSensor0"
        private String contactState = "closed"
+       private String currentContact = "closed"
        private String latestValue = "closed"
+       private String alarmState = "armed"
 
                
        ContactSensors(Closure sendEvent, int deviceNumbers) {
@@ -20,7 +25,7 @@ public class ContactSensors {
                this.deviceNumbers = deviceNumbers
                this.contacts = []
 
-               contacts.add(new ContactSensor(id, label, displayName, this.contactState, this.latestValue))
+               contacts.add(new ContactSensor(id, label, displayName, this.contactState, this.currentContact, this.alarmState, this.latestValue))
        }
 
        //Methods for closures
@@ -36,22 +41,46 @@ public class ContactSensors {
        def find(Closure Input) {
                contacts.find(Input)
        }
+       def sort(Closure Input) {
+               contacts.sort(Input)
+       }
        def collect(Closure Input) {
                contacts.collect(Input)
        }
 
        //By Model Checker
        def setValue(LinkedHashMap eventDataMap) {
-               contacts[0].setValue(eventDataMap["value"])
-               this.latestValue = contacts[0].latestValue
-               this.contactState = contacts[0].contactState
-               sendEvent(eventDataMap)
+               if (eventDataMap["value"] != contacts[0].contactState) {
+                       this.latestValue = eventDataMap["value"]
+                       this.contactState = eventDataMap["value"]
+                       this.currentContact = eventDataMap["value"]
+                       contacts[0].setValue(eventDataMap["value"])
+                       sendEvent(eventDataMap)
+               }
+       }
+
+       def eventsSince(Date dateObj) {
+               return contacts[0].eventsSince()
+       }
+
+       def on() {
+               this.alarmState = "armed"
+               contacts[0].on()
+       }
+
+       def 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
        }