X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=Lock%2FLocks.groovy;h=d65e3f6033c2127bfc72ac9838766844133d3575;hb=d0b538d93e64c63d2673796db08570953b57f947;hp=ad297ab8ed2512c5740582a8fd28324443e5bdff;hpb=2932def9bb947d617975235763f7338360f0e5a4;p=smartthings-infrastructure.git diff --git a/Lock/Locks.groovy b/Lock/Locks.groovy index ad297ab..d65e3f6 100644 --- a/Lock/Locks.groovy +++ b/Lock/Locks.groovy @@ -1,126 +1,51 @@ //Create a class for lock device package Lock -import Timer.SimulatedTimer +import SmartThing.SmartThings -public class Locks{ - int deviceNumbers - List locks - def sendEvent - def timers +public class Locks extends SmartThing { + List locks = new ArrayList() - //When we have only one device - private String id = "lockID0" - private String label = "lock0" - private String displayName = "lock0" - private String lockState = "locked" - private String currentLock = "locked" - private String lockLatestValue = "locked" + Locks(Closure sendEvent, boolean init) { + // Only initialize one time since we only have one device for each capability + thermostats = smartThings - Locks(Closure sendEvent, int deviceNumbers, boolean init) { - this.sendEvent = sendEvent - this.timers = new SimulatedTimer() - this.deviceNumbers = deviceNumbers - this.locks = [] + // Initialization + StringBuilder id = new StringBuilder("lockID0") + StringBuilder label = new StringBuilder("lock") + StringBuilder displayName = new StringBuilder("lock0") + StringBuilder lock = new StringBuilder() - 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)) + if (init) + lock.append("locked") + else + lock.append("unlocked") + + locks.add(new Lock(sendEvent,id, label, displayName, lock)) } - //By Apps + // Methods to set values def lock() { - if (lockState != "locked") { - //lockLatestValue = lockState - lockLatestValue = "locked" - lockState = "locked" - currentLock = "locked" - locks[0].lock() - } + lock[0].lock() } def lock(LinkedHashMap metaData) { - if (lockState != "locked") { - def task = timers.runAfter(metaData["delay"]) { - //lockLatestValue = lockState - lockLatestValue = "locked" - lockState = "locked" - currentLock = "locked" - locks[0].lock() - } - } + lock() } def unlock() { - if (lockState != "unlocked") { - //lockLatestValue = lockState - lockLatestValue = "unlocked" - lockState = "unlocked" - currentLock = "unlocked" - locks[0].unlock() - } + lock[0].unlock() } def unlock(LinkedHashMap metaData) { - if (lockState != "unlocked") { - def task = timers.runAfter(metaData["delay"]) { - //lockLatestValue = lockState - lockLatestValue = "unlocked" - lockState = "unlocked" - currentLock = "unlocked" - locks[0].unlock() - } - } - } - - //Methods for closures - def count(Closure Input) { - locks.count(Input) - } - def size() { - locks.size() - } - def each(Closure Input) { - locks.each(Input) - } - def find(Closure Input) { - locks.find(Input) - } - def sort(Closure Input) { - locks.sort(Input) - } - def collect(Closure Input) { - locks.collect(Input) - } - - //By Model Checker - def setValue(LinkedHashMap 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) { - locks[0].currentValue(deviceFeature) - } - - def latestValue(String deviceFeature) { - locks[0].latestValue(deviceFeature) + unlock() } - def getAt(int ix) { - locks[ix] + // Methods to return values + def getCurrentLock() { + List tmpValues = new ArrayList() + tmpValues.add(locks[0].getCurrentLock()) + return tmpValues } }