//Create a class for lock device package Lock import Timer.SimulatedTimer public class Locks { private int id private String displayName private String lockState private String lockLatestValue def sendEvent def timers Locks(Closure sendEvent, int id, String displayName, String lockState, String lockLatestValue) { this.id = id this.sendEvent = sendEvent this.displayName = displayName this.lockState = lockState this.lockLatestValue = lockLatestValue this.timers = new SimulatedTimer() } //By Apps def lock() { println("the door with id:$id is locked!") this.lockLatestValue = this.lockState this.lockState = "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.lockState this.lockState = "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.lockState this.lockState = "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.lockState this.lockState = "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.lockState this.lockState = value } def currentValue(String deviceFeature) { if (deviceFeature == "lock") { return lockState } } def latestValue(String deviceFeature) { if (deviceFeature == "lock") { return lockLatestValue } } }