1 //Create a class for lock device
3 import SmartThing.SmartThing
5 public class Lock extends SmartThing {
6 // id, label, and display name of the device
7 StringBuilder id = new StringBuilder()
8 StringBuilder label = new StringBuilder()
9 StringBuilder displayName = new StringBuilder()
10 // Features with string values
11 StringBuilder currentLock = new StringBuilder()
12 // Maps from features to values
13 HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
16 Lock(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentLock) {
17 deviceValuesMap = deviceValueSmartThing
19 labelSmartThing = label
20 displayNameSmartThing = displayName
21 sendEventSmartThings = sendEvent
26 this.displayName = displayName
27 this.currentLock = currentLock
29 deviceValuesMap.put("lock", currentLock)
32 // Methods to set values
34 action(currentLock, "locked")
37 def lock(LinkedHashMap metaData) {
42 action(currentLock, "unlocked")
45 def unlock(LinkedHashMap metaData) {
49 def action(StringBuilder variable, String newValue) {
50 if (!variable.toString().equals(newValue)) {
51 String tmpID = id.toString()
52 variable.replace(0, variable.length(), newValue)
53 println("Lock with id:$tmpID is changed to $newValue!")
54 sendEvent([name: "lock", value: newValue, deviceId: tmpID, descriptionText: "",
55 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
59 // Methods to return values
60 def getCurrentLock() {
61 return currentLock.toString()