1 //Create a class for lock device
3 import Timer.SimulatedTimer
8 private String displayName
9 private String lockState
10 private String currentLock
11 private String lockLatestValue
16 Lock(Closure sendEvent, int id, String label, String displayName, String lockState, String lockLatestValue) {
19 this.sendEvent = sendEvent
20 this.displayName = displayName
21 this.lockState = lockState
22 this.currentLock = lockState
23 this.lockLatestValue = lockLatestValue
24 this.timers = new SimulatedTimer()
29 println("the door with id:$id is locked!")
30 this.lockLatestValue = this.lockState
31 this.lockState = "locked"
32 this.currentLock = "locked"
33 sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "",
34 displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
37 def lock(LinkedHashMap metaData) {
38 def task = timers.runAfter(metaData["delay"]) {
39 println("the door with id:$id is locked!")
40 this.lockLatestValue = this.lockState
41 this.lockState = "locked"
42 this.currentLock = "locked"
43 sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "",
44 displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
49 println("the door with id:$id is unlocked!")
50 this.lockLatestValue = this.lockState
51 this.lockState = "unlocked"
52 this.currentLock = "unlocked"
53 sendEvent([name: "unlock", value: "unlocked", deviceId: this.id, descriptionText: "",
54 displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
57 def unlock(LinkedHashMap metaData) {
58 def task = timers.runAfter(metaData["delay"]) {
59 println("the door with id:$id is locked!")
60 this.lockLatestValue = this.lockState
61 this.lockState = "locked"
62 this.currentLock = "locked"
63 sendEvent([name: "unlock", value: "unlocked", deviceId: this.id, descriptionText: "",
64 displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
69 def setValue(String value) {
70 println("the door with id:$id is $value!")
71 this.lockLatestValue = this.lockState
72 this.lockState = value
73 this.currentLock = value
76 def currentValue(String deviceFeature) {
77 if (deviceFeature == "lock") {
82 def latestValue(String deviceFeature) {
83 if (deviceFeature == "lock") {
84 return lockLatestValue