1 //Create a class for lock device
3 import Timer.SimulatedTimer
11 //When we have only one device
12 private String id = "lockID0"
13 private String label = "lock0"
14 private String displayName = "lock0"
15 private String lockState = "locked"
16 private String currentLock = "locked"
17 private String lockLatestValue = "locked"
19 Locks(Closure sendEvent, int deviceNumbers, boolean init) {
20 this.sendEvent = sendEvent
21 this.timers = new SimulatedTimer()
22 this.deviceNumbers = deviceNumbers
26 this.lockState = "locked"
27 this.currentLock = "locked"
28 this.lockLatestValue = "locked"
30 this.lockState = "unlocked"
31 this.currentLock = "unlocked"
32 this.lockLatestValue = "unlocked"
34 locks.add(new Lock(sendEvent,id, label, displayName, this.lockState, this.lockLatestValue))
39 if (lockState != "locked") {
40 //lockLatestValue = lockState
41 lockLatestValue = "locked"
43 currentLock = "locked"
48 def lock(LinkedHashMap metaData) {
49 if (lockState != "locked") {
50 def task = timers.runAfter(metaData["delay"]) {
51 //lockLatestValue = lockState
52 lockLatestValue = "locked"
54 currentLock = "locked"
61 if (lockState != "unlocked") {
62 //lockLatestValue = lockState
63 lockLatestValue = "unlocked"
64 lockState = "unlocked"
65 currentLock = "unlocked"
71 def unlock(LinkedHashMap metaData) {
72 if (lockState != "unlocked") {
73 def task = timers.runAfter(metaData["delay"]) {
74 //lockLatestValue = lockState
75 lockLatestValue = "unlocked"
76 lockState = "unlocked"
77 currentLock = "unlocked"
83 //Methods for closures
84 def count(Closure Input) {
90 def each(Closure Input) {
93 def find(Closure Input) {
96 def sort(Closure Input) {
99 def collect(Closure Input) {
104 def setValue(LinkedHashMap eventDataMap) {
105 if (eventDataMap["value"] != locks[0].lockState) {
106 locks[0].setValue(eventDataMap["value"])
107 this.lockState = locks[0].lockState
108 this.currentLock = locks[0].lockState
109 this.lockLatestValue = locks[0].lockLatestValue
110 sendEvent(eventDataMap)
114 def currentValue(String deviceFeature) {
115 locks[0].currentValue(deviceFeature)
118 def latestValue(String deviceFeature) {
119 locks[0].latestValue(deviceFeature)