Commit #7: Events thread-based + new easier Extractor.py + our own Timer class
[smartthings-infrastructure.git] / ContactSensor / Contacting.groovy
index 9b293e877bffeb109d7f0e35c096e9b68f2f4852..a744889f438edb8cfbeb438579e13efe29e2d820 100644 (file)
@@ -1,17 +1,27 @@
 //Create a class for contact sensor
 package ContactSensor
+import Timer.SimulatedTimer
 
-public class Contacting{
+public class Contacting {
        private int deviceNumbers
        private List contacts
        def sendEvent
+
+       //For one device(We cannot have obj.id)-> We should have obj[0].id
+       private int id = 0
+       private String displayName = "contact0"
+       private String contactState = "closed"
+       private String contactLatestValue = "closed"
+
                
        Contacting(Closure sendEvent, int deviceNumbers) {
                this.sendEvent = sendEvent              
                this.deviceNumbers = deviceNumbers
                this.contacts = []
+
+
                if (deviceNumbers == 1) {
-                       contacts = [new Contacts(0, "contact0", "closed", "closed")]
+                       contacts = [new Contacts(this.id, this.displayName, this.contactState, this.contactLatestValue)]
                } else if (deviceNumbers == 2) {
                        contacts = [new Contacts(0, "contact0", "closed", "closed"), new Contacts(1, "contact1", "closed", "closed")]
                } else if (deviceNumbers == 3) {
@@ -23,6 +33,9 @@ public class Contacting{
        //By Model Checker
        def setValue(LinkedHashMap eventDataMap) {
                contacts[eventDataMap["deviceId"]].setValue(eventDataMap["value"])
+               if (deviceNumbers == 1)
+                       this.contactLatestValue = contacts[eventDataMap["deviceId"]].contactLatestValue
+                       this.contactState = contacts[eventDataMap["deviceId"]].contactState
                sendEvent(eventDataMap)
        }