1 //Create a class for lock device
6 private String displayName
7 private String lockCurrentValue
8 private String lockLatestValue
13 Locks(Closure sendEvent, int id, String displayName, String lockCurrentValue, String lockLatestValue) {
15 this.sendEvent = sendEvent
16 this.displayName = displayName
17 this.lockCurrentValue = lockCurrentValue
18 this.lockLatestValue = lockLatestValue
19 this.timers = new Timer()
20 timers.cancel() //Timer is ready to use
25 println("the door with id:$id is locked!")
26 this.lockLatestValue = this.lockCurrentValue
27 this.lockCurrentValue = "locked"
28 sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "",
29 displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
32 def lock(LinkedHashMap metaData) {
33 def task = timers.runAfter(metaData["delay"]) {
34 println("the door with id:$id is locked!")
35 this.lockLatestValue = this.lockCurrentValue
36 this.lockCurrentValue = "locked"
37 sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "",
38 displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
43 println("the door with id:$id is unlocked!")
44 this.lockLatestValue = this.lockCurrentValue
45 this.lockCurrentValue = "unlocked"
46 sendEvent([name: "lock", value: "unlocked", deviceId: this.id, descriptionText: "",
47 displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
50 def unlock(LinkedHashMap metaData) {
51 def task = timers.runAfter(metaData["delay"]) {
52 println("the door with id:$id is locked!")
53 this.lockLatestValue = this.lockCurrentValue
54 this.lockCurrentValue = "locked"
55 sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "",
56 displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
61 def setValue(String value) {
62 println("the door with id:$id is $value!")
63 this.lockLatestValue = this.lockCurrentValue
64 this.lockCurrentValue = value
67 def currentValue(String deviceFeature) {
68 if (deviceFeature == "lock") {
69 return lockCurrentValue
73 def latestValue(String deviceFeature) {
74 if (deviceFeature == "lock") {
75 return lockLatestValue