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()
24 println("the door with id:$id is locked!")
25 this.lockLatestValue = this.lockCurrentValue
26 this.lockCurrentValue = "locked"
27 sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "",
28 displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
31 def lock(LinkedHashMap metaData) {
32 def task = timers.runAfter(metaData["delay"]) {
33 println("the door with id:$id is locked!")
34 this.lockLatestValue = this.lockCurrentValue
35 this.lockCurrentValue = "locked"
36 sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "",
37 displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
42 println("the door with id:$id is unlocked!")
43 this.lockLatestValue = this.lockCurrentValue
44 this.lockCurrentValue = "unlocked"
45 sendEvent([name: "unlock", value: "unlocked", deviceId: this.id, descriptionText: "",
46 displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
49 def unlock(LinkedHashMap metaData) {
50 def task = timers.runAfter(metaData["delay"]) {
51 println("the door with id:$id is locked!")
52 this.lockLatestValue = this.lockCurrentValue
53 this.lockCurrentValue = "locked"
54 sendEvent([name: "unlock", value: "unlocked", deviceId: this.id, descriptionText: "",
55 displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
60 def setValue(String value) {
61 println("the door with id:$id is $value!")
62 this.lockLatestValue = this.lockCurrentValue
63 this.lockCurrentValue = value
66 def currentValue(String deviceFeature) {
67 if (deviceFeature == "lock") {
68 return lockCurrentValue
72 def latestValue(String deviceFeature) {
73 if (deviceFeature == "lock") {
74 return lockLatestValue