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 = "locked"
32 this.lockState = "locked"
33 this.currentLock = "locked"
34 sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "",
35 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
39 def lock(LinkedHashMap metaData) {
40 if (lockState != "locked") {
41 def task = timers.runAfter(metaData["delay"]) {
42 println("the door with id:$id is locked!")
43 this.lockLatestValue = "locked"
44 this.lockState = "locked"
45 this.currentLock = "locked"
46 sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "",
47 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
53 if (lockState != "unlocked") {
54 println("the door with id:$id is unlocked!")
55 this.lockLatestValue = "unlocked"
56 this.lockState = "unlocked"
57 this.currentLock = "unlocked"
58 sendEvent([name: "lock", value: "unlocked", deviceId: this.id, descriptionText: "",
59 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
63 def unlock(LinkedHashMap metaData) {
64 if (lockState != "unlocked") {
65 def task = timers.runAfter(metaData["delay"]) {
66 println("the door with id:$id is locked!")
67 this.lockLatestValue = "unlocked"
68 this.lockState = "unlocked"
69 this.currentLock = "unlocked"
70 sendEvent([name: "lock", value: "unlocked", deviceId: this.id, descriptionText: "",
71 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
77 def setValue(String value) {
78 println("the door with id:$id is $value!")
79 this.lockLatestValue = value
80 this.lockState = value
81 this.currentLock = value
84 def currentValue(String deviceFeature) {
85 if (deviceFeature == "lock") {
90 def latestValue(String deviceFeature) {
91 if (deviceFeature == "lock") {
92 return lockLatestValue