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) {
20 this.sendEvent = sendEvent
21 this.timers = new SimulatedTimer()
22 this.deviceNumbers = deviceNumbers
25 locks.add(new Lock(sendEvent,id, label, displayName, this.lockState, this.lockLatestValue))
31 lockLatestValue = lockState
33 currentLock = "locked"
36 def lock(LinkedHashMap metaData) {
37 def task = timers.runAfter(metaData["delay"]) {
39 lockLatestValue = lockState
41 currentLock = "locked"
47 lockLatestValue = lockState
48 lockState = "unlocked"
49 currentLock = "unlocked"
53 def unlock(LinkedHashMap metaData) {
54 def task = timers.runAfter(metaData["delay"]) {
56 lockLatestValue = lockState
57 lockState = "unlocked"
58 currentLock = "unlocked"
62 //Methods for closures
63 def count(Closure Input) {
69 def each(Closure Input) {
72 def find(Closure Input) {
75 def collect(Closure Input) {
80 def setValue(LinkedHashMap eventDataMap) {
81 if (eventDataMap["value"] != locks[0].lockState) {
82 locks[0].setValue(eventDataMap["value"])
83 this.lockState = locks[0].lockState
84 this.currentLock = locks[0].lockState
85 this.lockLatestValue = locks[0].lockLatestValue
86 sendEvent(eventDataMap)
90 def currentValue(String deviceFeature) {
91 locks[0].currentValue(deviceFeature)
94 def latestValue(String deviceFeature) {
95 locks[0].latestValue(deviceFeature)