Removing getXXX methods + properties. Adding getProperty feature to SmartThing(s)
[smartthings-infrastructure.git] / Lock / Locks.groovy
index ea75ef3e4863611aa4ed92cd989eebd382cf8c96..37deb0ac2a2b02dc62bfa3a008d0cf0042003ea3 100644 (file)
 //Create a class for lock device
 package Lock
-import Timer.SimulatedTimer
+import SmartThing.SmartThings
 
-//JPF's Verify API
-import gov.nasa.jpf.vm.Verify
+public class Locks extends SmartThings {
+       List locks = new ArrayList()
 
-public class Locks{
-       int deviceNumbers       
-       List locks      
-       def sendEvent   
-       def timers
+       Locks(Closure sendEvent, boolean init) {
+               // Only initialize one time since we only have one device for each capability
+               locks = smartThings
 
-       //When we have only one device
-       private String id = "lockID0"
-       private String label = "lock0"
-       private String displayName = "lock0"
-       private String lockState = "locked"
-       private String currentLock = "locked"
-       private String lockLatestValue = "locked"
+               // Initialization
+               String id = "lockID0"
+               String label = "lock"
+               String displayName = "lock"
+               String lock
 
-       Locks(Closure sendEvent, int deviceNumbers) {
-               this.sendEvent = sendEvent
-               this.timers = new SimulatedTimer()
-               this.deviceNumbers = deviceNumbers
-               this.locks = []
+               if (init)
+                       lock = "locked"
+               else
+                       lock = "unlocked"
 
-               def init = Verify.getBoolean()
-               if (init) {
-                       this.lockState = "locked"
-                       this.lockLatestValue = "locked"
-               } else {
-                       this.lockState = "unlocked"
-                       this.lockLatestValue = "unlocked"
-               }
-               locks.add(new Lock(sendEvent,id, label, displayName, this.lockState, this.lockLatestValue))
+               locks.add(new Lock(sendEvent, id, label, displayName, lock))
        }
 
-       //By Apps
+       // Methods to set values
        def lock() {
-               if (lockState != "locked") {
-                       locks[0].lock()
-                       lockLatestValue = lockState
-                       lockState = "locked"
-                       currentLock = "locked"
-               }
+               lock[0].lock()
        }
 
        def lock(LinkedHashMap metaData) {
-               if (lockState != "locked") {
-                       def task = timers.runAfter(metaData["delay"]) {
-                               locks[0].lock()
-                               lockLatestValue = lockState
-                               lockState = "locked"
-                               currentLock = "locked"
-                       }
-               }
+               lock()
        }
 
        def unlock() {
-               if (lockState != "unlocked") {
-                       locks[0].unlock()
-                       lockLatestValue = lockState
-                       lockState = "unlocked"
-                       currentLock = "unlocked"
-               }
+               lock[0].unlock()
        }
 
 
        def unlock(LinkedHashMap metaData) {
-               if (lockState != "unlocked") {
-                       def task = timers.runAfter(metaData["delay"]) {
-                               locks[0].unlock()
-                               lockLatestValue = lockState
-                               lockState = "unlocked"
-                               currentLock = "unlocked"
-                       }
-               }
-       }
-
-       //Methods for closures
-       def count(Closure Input) {
-               locks.count(Input)
-       }
-       def size() {
-               locks.size()
-       }
-       def each(Closure Input) {
-               locks.each(Input)
-       }
-       def find(Closure Input) {
-               locks.find(Input)
-       }
-       def collect(Closure Input) {
-               locks.collect(Input)
-       }
-
-       //By Model Checker
-       def setValue(LinkedHashMap eventDataMap) {
-               if (eventDataMap["value"] != locks[0].lockState) {
-                       locks[0].setValue(eventDataMap["value"])
-                       this.lockState = locks[0].lockState
-                       this.currentLock = locks[0].lockState
-                       this.lockLatestValue = locks[0].lockLatestValue
-                       sendEvent(eventDataMap)
-               }
-       }
-
-       def currentValue(String deviceFeature) {
-               locks[0].currentValue(deviceFeature)
-       }
-
-       def latestValue(String deviceFeature) {
-               locks[0].latestValue(deviceFeature)
-       }
-
-       def getAt(int ix) {
-               locks[ix]
+               unlock()
        }
 }