Adding missing methods.
[smartthings-infrastructure.git] / Lock / Lock.groovy
index 76482b4f3262191209360437f60a9343cc8e0337..1b2e472c27a7504343bc4cedb15bb246a0c8e62c 100644 (file)
@@ -28,7 +28,7 @@ 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"
                        sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "",
@@ -40,7 +40,7 @@ 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"
                                sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "",
@@ -52,10 +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"}'])
                }
        }
@@ -64,11 +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.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"}'])                             
                        }
                }
        }
@@ -76,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
        }