1 //Create a class for lock device
3 import Timer.SimulatedTimer
7 private String displayName
8 private String lockState
9 private String lockLatestValue
14 Locks(Closure sendEvent, int id, String displayName, String lockState, String lockLatestValue) {
16 this.sendEvent = sendEvent
17 this.displayName = displayName
18 this.lockState = lockState
19 this.lockLatestValue = lockLatestValue
20 this.timers = new SimulatedTimer()
25 println("the door with id:$id is locked!")
26 this.lockLatestValue = this.lockState
27 this.lockState = "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.lockState
36 this.lockState = "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.lockState
45 this.lockState = "unlocked"
46 sendEvent([name: "unlock", 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.lockState
54 this.lockState = "locked"
55 sendEvent([name: "unlock", value: "unlocked", 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.lockState
64 this.lockState = value
67 def currentValue(String deviceFeature) {
68 if (deviceFeature == "lock") {
73 def latestValue(String deviceFeature) {
74 if (deviceFeature == "lock") {
75 return lockLatestValue