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, String 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 if (lockState != "locked") {
30 println("the door with id:$id is locked!")
31 //this.lockLatestValue = this.lockState
32 this.lockLatestValue = "locked"
33 this.lockState = "locked"
34 this.currentLock = "locked"
35 sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "",
36 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
40 def lock(LinkedHashMap metaData) {
41 if (lockState != "locked") {
42 def task = timers.runAfter(metaData["delay"]) {
43 println("the door with id:$id is locked!")
44 //this.lockLatestValue = this.lockState
45 this.lockLatestValue = "locked"
46 this.lockState = "locked"
47 this.currentLock = "locked"
48 sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "",
49 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
55 if (lockState != "unlocked") {
56 println("the door with id:$id is unlocked!")
57 //this.lockLatestValue = this.lockState
58 this.lockLatestValue = "unlocked"
59 this.lockState = "unlocked"
60 this.currentLock = "unlocked"
61 sendEvent([name: "unlock", value: "unlocked", deviceId: this.id, descriptionText: "",
62 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
63 sendEvent([name: "lock", value: "unlocked", deviceId: this.id, descriptionText: "",
64 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
68 def unlock(LinkedHashMap metaData) {
69 if (lockState != "unlocked") {
70 def task = timers.runAfter(metaData["delay"]) {
71 println("the door with id:$id is locked!")
72 //this.lockLatestValue = this.lockState
73 this.lockLatestValue = "locked"
74 this.lockState = "locked"
75 this.currentLock = "locked"
76 sendEvent([name: "unlock", value: "unlocked", deviceId: this.id, descriptionText: "",
77 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
78 sendEvent([name: "lock", value: "unlocked", deviceId: this.id, descriptionText: "",
79 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
85 def setValue(String value) {
86 println("the door with id:$id is $value!")
87 this.lockLatestValue = this.lockState
88 this.lockState = value
89 this.currentLock = value
92 def currentValue(String deviceFeature) {
93 if (deviceFeature == "lock") {
98 def latestValue(String deviceFeature) {
99 if (deviceFeature == "lock") {
100 return lockLatestValue