X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=Lock%2FLocks.groovy;h=ad297ab8ed2512c5740582a8fd28324443e5bdff;hb=591f965b054a99429e5f0c7c44078a58bcc38e06;hp=f792c6ccfda41d3f5d36d8ec77ae1436ffc85a7d;hpb=b8c0c6eb635704be056e1e4f373620e2bb05b775;p=smartthings-infrastructure.git diff --git a/Lock/Locks.groovy b/Lock/Locks.groovy index f792c6c..ad297ab 100644 --- a/Lock/Locks.groovy +++ b/Lock/Locks.groovy @@ -16,46 +16,67 @@ public class Locks{ private String currentLock = "locked" private String lockLatestValue = "locked" - Locks(Closure sendEvent, int deviceNumbers) { + Locks(Closure sendEvent, int deviceNumbers, boolean init) { this.sendEvent = sendEvent this.timers = new SimulatedTimer() this.deviceNumbers = deviceNumbers this.locks = [] + if (init) { + this.lockState = "locked" + this.currentLock = "locked" + this.lockLatestValue = "locked" + } else { + this.lockState = "unlocked" + this.currentLock = "unlocked" + this.lockLatestValue = "unlocked" + } locks.add(new Lock(sendEvent,id, label, displayName, this.lockState, this.lockLatestValue)) } //By Apps def lock() { - locks[0].lock() - lockLatestValue = lockState - lockState = "locked" - currentLock = "locked" + if (lockState != "locked") { + //lockLatestValue = lockState + lockLatestValue = "locked" + lockState = "locked" + currentLock = "locked" + locks[0].lock() + } } def lock(LinkedHashMap metaData) { - def task = timers.runAfter(metaData["delay"]) { - locks[0].lock() - lockLatestValue = lockState - lockState = "locked" - currentLock = "locked" + if (lockState != "locked") { + def task = timers.runAfter(metaData["delay"]) { + //lockLatestValue = lockState + lockLatestValue = "locked" + lockState = "locked" + currentLock = "locked" + locks[0].lock() + } } } def unlock() { - locks[0].unlock() - lockLatestValue = lockState - lockState = "unlocked" - currentLock = "unlocked" + if (lockState != "unlocked") { + //lockLatestValue = lockState + lockLatestValue = "unlocked" + lockState = "unlocked" + currentLock = "unlocked" + locks[0].unlock() + } } def unlock(LinkedHashMap metaData) { - def task = timers.runAfter(metaData["delay"]) { - locks[0].unlock() - lockLatestValue = lockState - lockState = "unlocked" - currentLock = "unlocked" + if (lockState != "unlocked") { + def task = timers.runAfter(metaData["delay"]) { + //lockLatestValue = lockState + lockLatestValue = "unlocked" + lockState = "unlocked" + currentLock = "unlocked" + locks[0].unlock() + } } } @@ -72,6 +93,9 @@ public class Locks{ def find(Closure Input) { locks.find(Input) } + def sort(Closure Input) { + locks.sort(Input) + } def collect(Closure Input) { locks.collect(Input) }