Commit #9: More classes + Extractor with Rahmadi's editions + Fixing some bugs
[smartthings-infrastructure.git] / Lock / Locks.groovy
index 6214b84d69dcaad46aa8e905dcfb7d7c64e88ace..f792c6ccfda41d3f5d36d8ec77ae1436ffc85a7d 100644 (file)
@@ -28,22 +28,34 @@ public class Locks{
        //By Apps
        def lock() {
                locks[0].lock()
+               lockLatestValue = lockState
+               lockState = "locked"
+               currentLock = "locked"
        }
 
        def lock(LinkedHashMap metaData) {
                def task = timers.runAfter(metaData["delay"]) {
                        locks[0].lock()
+                       lockLatestValue = lockState
+                       lockState = "locked"
+                       currentLock = "locked"
                }
        }
 
        def unlock() {
                locks[0].unlock()
+               lockLatestValue = lockState
+               lockState = "unlocked"
+               currentLock = "unlocked"
        }
 
 
        def unlock(LinkedHashMap metaData) {
                def task = timers.runAfter(metaData["delay"]) {
                        locks[0].unlock()
+                       lockLatestValue = lockState
+                       lockState = "unlocked"
+                       currentLock = "unlocked"
                }
        }
 
@@ -66,11 +78,13 @@ public class Locks{
 
        //By Model Checker
        def setValue(LinkedHashMap eventDataMap) {
-               locks[0].setValue(eventDataMap["value"])
-               this.lockState = locks[0].lockState
-               this.currentLock = locks[0].lockState
-               this.lockLatestValue = locks[0].lockLatestValue
-               sendEvent(eventDataMap)
+               if (eventDataMap["value"] != locks[0].lockState) {
+                       locks[0].setValue(eventDataMap["value"])
+                       this.lockState = locks[0].lockState
+                       this.currentLock = locks[0].lockState
+                       this.lockLatestValue = locks[0].lockLatestValue
+                       sendEvent(eventDataMap)
+               }
        }
 
        def currentValue(String deviceFeature) {