def timers
//When we have only one device
- private int id = 20
- private String label = "lock"
- private String displayName = "lock"
+ 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, int deviceNumbers) {
+ Locks(Closure sendEvent, int deviceNumbers, boolean init) {
this.sendEvent = sendEvent
this.timers = new SimulatedTimer()
this.deviceNumbers = deviceNumbers
this.locks = []
- for (int i = 0;i < deviceNumbers;i++) {
- locks.add(new Lock(sendEvent, i+20, label+i.toString(), displayName+i.toString(), this.lockState, this.lockLatestValue))
+
+ 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*.lock()
+ 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*.lock()
+ if (lockState != "locked") {
+ def task = timers.runAfter(metaData["delay"]) {
+ //lockLatestValue = lockState
+ lockLatestValue = "locked"
+ lockState = "locked"
+ currentLock = "locked"
+ locks[0].lock()
+ }
}
}
def unlock() {
- locks*.unlock()
+ 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*.unlock()
+ if (lockState != "unlocked") {
+ def task = timers.runAfter(metaData["delay"]) {
+ //lockLatestValue = lockState
+ lockLatestValue = "unlocked"
+ lockState = "unlocked"
+ currentLock = "unlocked"
+ locks[0].unlock()
+ }
}
}
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) {
- locks[eventDataMap["deviceId"]].setValue(eventDataMap["value"])
- if (deviceNumbers == 1)
- this.lockState = locks[eventDataMap["deviceId"]].lockState
- this.currentLock = locks[eventDataMap["deviceId"]].lockState
- this.lockLatestValue = locks[eventDataMap["deviceId"]].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) {
- if (deviceNumbers == 1)
- locks[0].currentValue(deviceFeature)
- else
- locks*.currentValue(deviceFeature)
+ locks[0].currentValue(deviceFeature)
}
def latestValue(String deviceFeature) {
- if (deviceNumbers == 1)
- locks[0].latestValue(deviceFeature)
- else
- locks*.latestValue(deviceFeature)
+ locks[0].latestValue(deviceFeature)
}
def getAt(int ix) {