Integrating List of constant names into the if-statement to avoid creating read/write...
[smartthings-infrastructure.git] / Lock / Lock.groovy
index 285fe53217dadf8514de4f32ecb8f60bd5a6afc6..1b2e472c27a7504343bc4cedb15bb246a0c8e62c 100644 (file)
@@ -28,7 +28,6 @@ public class Lock {
        def lock() {
                if (lockState != "locked") {
                        println("the door with id:$id is locked!")
-                       //this.lockLatestValue = this.lockState
                        this.lockLatestValue = "locked"
                        this.lockState = "locked"
                        this.currentLock = "locked"
@@ -41,7 +40,6 @@ public class Lock {
                if (lockState != "locked") {
                        def task = timers.runAfter(metaData["delay"]) {
                                println("the door with id:$id is locked!")
-                               //this.lockLatestValue = this.lockState
                                this.lockLatestValue = "locked"
                                this.lockState = "locked"
                                this.currentLock = "locked"
@@ -54,11 +52,10 @@ public class Lock {
        def unlock() {
                if (lockState != "unlocked") {
                        println("the door with id:$id is unlocked!")
-                       //this.lockLatestValue = this.lockState
                        this.lockLatestValue = "unlocked"
                        this.lockState = "unlocked"
                        this.currentLock = "unlocked"
-                       sendEvent([name: "unlock", value: "unlocked", deviceId: this.id, descriptionText: "",
+                       sendEvent([name: "lock", value: "unlocked", deviceId: this.id, descriptionText: "",
                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }
@@ -67,12 +64,11 @@ public class Lock {
                if (lockState != "unlocked") {
                        def task = timers.runAfter(metaData["delay"]) {
                                println("the door with id:$id is locked!")
-                               //this.lockLatestValue = this.lockState
-                               this.lockLatestValue = "locked"
-                               this.lockState = "locked"
-                               this.currentLock = "locked"
-                               sendEvent([name: "unlock", value: "unlocked", deviceId: this.id, descriptionText: "",
-                                         displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+                               this.lockLatestValue = "unlocked"
+                               this.lockState = "unlocked"
+                               this.currentLock = "unlocked"
+                               sendEvent([name: "lock", value: "unlocked", deviceId: this.id, descriptionText: "",
+                                         displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])                             
                        }
                }
        }
@@ -80,7 +76,7 @@ public class Lock {
        //By Model Checker
        def setValue(String value) {
                println("the door with id:$id is $value!")
-               this.lockLatestValue = this.lockState
+               this.lockLatestValue = value
                this.lockState = value
                this.currentLock = value
        }