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!")
33 //this.lockLatestValue = this.lockState
34 >>>>>>> a02c9807815a35c0f57241ee6510a3d312499049
35 this.lockLatestValue = "locked"
36 this.lockState = "locked"
37 this.currentLock = "locked"
38 sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "",
39 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
40 sendEvent([name: "lock.locked", value: "locked", deviceId: this.id, descriptionText: "",
41 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
45 def lock(LinkedHashMap metaData) {
46 if (lockState != "locked") {
47 def task = timers.runAfter(metaData["delay"]) {
48 println("the door with id:$id is locked!")
51 //this.lockLatestValue = this.lockState
52 >>>>>>> a02c9807815a35c0f57241ee6510a3d312499049
53 this.lockLatestValue = "locked"
54 this.lockState = "locked"
55 this.currentLock = "locked"
56 sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "",
57 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
58 sendEvent([name: "lock.locked", value: "locked", deviceId: this.id, descriptionText: "",
59 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
65 if (lockState != "unlocked") {
66 println("the door with id:$id is unlocked!")
69 //this.lockLatestValue = this.lockState
70 >>>>>>> a02c9807815a35c0f57241ee6510a3d312499049
71 this.lockLatestValue = "unlocked"
72 this.lockState = "unlocked"
73 this.currentLock = "unlocked"
74 sendEvent([name: "unlock", value: "unlocked", deviceId: this.id, descriptionText: "",
75 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
76 sendEvent([name: "lock", value: "unlocked", deviceId: this.id, descriptionText: "",
77 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
79 sendEvent([name: "lock.unlocked", value: "unlocked", deviceId: this.id, descriptionText: "",
80 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
82 >>>>>>> a02c9807815a35c0f57241ee6510a3d312499049
86 def unlock(LinkedHashMap metaData) {
87 if (lockState != "unlocked") {
88 def task = timers.runAfter(metaData["delay"]) {
89 println("the door with id:$id is locked!")
91 this.lockLatestValue = "unlocked"
92 this.lockState = "unlocked"
93 this.currentLock = "unlocked"
94 sendEvent([name: "unlock", value: "unlocked", deviceId: this.id, descriptionText: "",
95 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
96 sendEvent([name: "lock", value: "unlocked", deviceId: this.id, descriptionText: "",
97 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
98 sendEvent([name: "lock.unlocked", value: "unlocked", deviceId: this.id, descriptionText: "",
99 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
101 //this.lockLatestValue = this.lockState
102 this.lockLatestValue = "locked"
103 this.lockState = "locked"
104 this.currentLock = "locked"
105 sendEvent([name: "unlock", value: "unlocked", deviceId: this.id, descriptionText: "",
106 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
107 sendEvent([name: "lock", value: "unlocked", deviceId: this.id, descriptionText: "",
108 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
109 >>>>>>> a02c9807815a35c0f57241ee6510a3d312499049
115 def setValue(String value) {
116 println("the door with id:$id is $value!")
117 this.lockLatestValue = value
118 this.lockState = value
119 this.currentLock = value
122 def currentValue(String deviceFeature) {
123 if (deviceFeature == "lock") {
128 def latestValue(String deviceFeature) {
129 if (deviceFeature == "lock") {
130 return lockLatestValue