Fixing a bug in locks: latestValue should have similar value with currentValue.
[smartthings-infrastructure.git] / Lock / Lock.groovy
index 76482b4f3262191209360437f60a9343cc8e0337..285fe53217dadf8514de4f32ecb8f60bd5a6afc6 100644 (file)
@@ -28,7 +28,8 @@ public class Lock {
        def lock() {
                if (lockState != "locked") {
                        println("the door with id:$id is locked!")
-                       this.lockLatestValue = this.lockState
+                       //this.lockLatestValue = this.lockState
+                       this.lockLatestValue = "locked"
                        this.lockState = "locked"
                        this.currentLock = "locked"
                        sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "",
@@ -40,7 +41,8 @@ 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 = this.lockState
+                               this.lockLatestValue = "locked"
                                this.lockState = "locked"
                                this.currentLock = "locked"
                                sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "",
@@ -52,7 +54,8 @@ public class Lock {
        def unlock() {
                if (lockState != "unlocked") {
                        println("the door with id:$id is unlocked!")
-                       this.lockLatestValue = this.lockState
+                       //this.lockLatestValue = this.lockState
+                       this.lockLatestValue = "unlocked"
                        this.lockState = "unlocked"
                        this.currentLock = "unlocked"
                        sendEvent([name: "unlock", value: "unlocked", deviceId: this.id, descriptionText: "",
@@ -64,7 +67,8 @@ 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 = this.lockState
+                               this.lockLatestValue = "locked"
                                this.lockState = "locked"
                                this.currentLock = "locked"
                                sendEvent([name: "unlock", value: "unlocked", deviceId: this.id, descriptionText: "",