//Create a class for lock device
package Lock
-import Timer.SimulatedTimer
+import SmartThing.SmartThings
-public class Locks {
- private int id
- private String displayName
- private String lockState
- private String lockLatestValue
- def sendEvent
- def timers
+public class Locks extends SmartThing {
+ List locks = new ArrayList()
+ Locks(Closure sendEvent, boolean init) {
+ // Only initialize one time since we only have one device for each capability
+ thermostats = smartThings
- Locks(Closure sendEvent, int id, String displayName, String lockState, String lockLatestValue) {
- this.id = id
- this.sendEvent = sendEvent
- this.displayName = displayName
- this.lockState = lockState
- this.lockLatestValue = lockLatestValue
- this.timers = new SimulatedTimer()
+ // Initialization
+ StringBuilder id = new StringBuilder("lockID0")
+ StringBuilder label = new StringBuilder("lock")
+ StringBuilder displayName = new StringBuilder("lock0")
+ StringBuilder lock = new StringBuilder()
+
+ if (init)
+ lock.append("locked")
+ else
+ lock.append("unlocked")
+
+ locks.add(new Lock(sendEvent,id, label, displayName, lock))
}
- //By Apps
+ // Methods to set values
def lock() {
- println("the door with id:$id is locked!")
- this.lockLatestValue = this.lockState
- this.lockState = "locked"
- sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ lock[0].lock()
}
def lock(LinkedHashMap metaData) {
- def task = timers.runAfter(metaData["delay"]) {
- println("the door with id:$id is locked!")
- this.lockLatestValue = this.lockState
- this.lockState = "locked"
- sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
- }
+ lock()
}
-
+
def unlock() {
- println("the door with id:$id is unlocked!")
- this.lockLatestValue = this.lockState
- this.lockState = "unlocked"
- sendEvent([name: "unlock", value: "unlocked", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ lock[0].unlock()
}
- def unlock(LinkedHashMap metaData) {
- def task = timers.runAfter(metaData["delay"]) {
- println("the door with id:$id is locked!")
- this.lockLatestValue = this.lockState
- this.lockState = "locked"
- sendEvent([name: "unlock", value: "unlocked", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
- }
- }
- //By Model Checker
- def setValue(String value) {
- println("the door with id:$id is $value!")
- this.lockLatestValue = this.lockState
- this.lockState = value
- }
-
- def currentValue(String deviceFeature) {
- if (deviceFeature == "lock") {
- return lockState
- }
+ def unlock(LinkedHashMap metaData) {
+ unlock()
}
- def latestValue(String deviceFeature) {
- if (deviceFeature == "lock") {
- return lockLatestValue
- }
+ // Methods to return values
+ def getCurrentLock() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(locks[0].getCurrentLock())
+ return tmpValues
}
}
+