//Create a class for lock device package Lock public class Locks { private int id private String displayName private String lockCurrentValue private String lockLatestValue def sendEvent def timers Locks(Closure sendEvent, int id, String displayName, String lockCurrentValue, String lockLatestValue) { this.id = id this.sendEvent = sendEvent this.displayName = displayName this.lockCurrentValue = lockCurrentValue this.lockLatestValue = lockLatestValue this.timers = new Timer() } //By Apps def lock() { println("the door with id:$id is locked!") this.lockLatestValue = this.lockCurrentValue this.lockCurrentValue = "locked" sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) } def lock(LinkedHashMap metaData) { def task = timers.runAfter(metaData["delay"]) { println("the door with id:$id is locked!") this.lockLatestValue = this.lockCurrentValue this.lockCurrentValue = "locked" sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) } } def unlock() { println("the door with id:$id is unlocked!") this.lockLatestValue = this.lockCurrentValue this.lockCurrentValue = "unlocked" sendEvent([name: "unlock", value: "unlocked", deviceId: this.id, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) } def unlock(LinkedHashMap metaData) { def task = timers.runAfter(metaData["delay"]) { println("the door with id:$id is locked!") this.lockLatestValue = this.lockCurrentValue this.lockCurrentValue = "locked" sendEvent([name: "unlock", value: "unlocked", deviceId: this.id, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) } } //By Model Checker def setValue(String value) { println("the door with id:$id is $value!") this.lockLatestValue = this.lockCurrentValue this.lockCurrentValue = value } def currentValue(String deviceFeature) { if (deviceFeature == "lock") { return lockCurrentValue } } def latestValue(String deviceFeature) { if (deviceFeature == "lock") { return lockLatestValue } } }