Commit #9: More classes + Extractor with Rahmadi's editions + Fixing some bugs
[smartthings-infrastructure.git] / ContactSensor / ContactSensors.groovy
index 10c4aa61aed7270292d1c03dc77ba2a18cf80a23..1de8c76dccd1ec2a90c08319dbf11236ba12333c 100644 (file)
@@ -12,7 +12,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 +22,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
@@ -42,10 +44,23 @@ public class ContactSensors {
 
        //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) {
+                       contacts[0].setValue(eventDataMap["value"])
+                       this.latestValue = contacts[0].latestValue
+                       this.contactState = contacts[0].contactState
+                       this.currentContact = contacts[0].contactState
+                       sendEvent(eventDataMap)
+               }
+       }
+
+       def on() {
+               contacts[0].on()
+               this.alarmState = "armed"
+       }
+
+       def off() {
+               contacts[0].off()
+               this.alarmState = "not armed"
        }
 
        def currentValue(String deviceFeature) {