//Create a class for lock device package Lock import SmartThing.SmartThing public class Lock extends SmartThing { // id, label, and display name of the device StringBuilder id = new StringBuilder() StringBuilder label = new StringBuilder() StringBuilder displayName = new StringBuilder() // Features with string values StringBuilder currentLock = new StringBuilder() // Maps from features to values HashMap deviceValuesMap = new HashMap() Lock(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentLock) { deviceValuesMap = deviceValueSmartThing idSmartThing = id labelSmartThing = label displayNameSmartThing = displayName sendEventSmartThings = sendEvent // Initialization this.id = id this.label = label this.displayName = displayName this.currentLock = currentLock deviceValuesMap.put("lock", currentLock) } // Methods to set values def lock() { action(currentLock, "locked") } def lock(LinkedHashMap metaData) { lock() } def unlock() { action(currentLock, "unlocked") } def unlock(LinkedHashMap metaData) { unlock() } def action(StringBuilder variable, String newValue) { if (!variable.toString().equals(newValue)) { String tmpID = id.toString() variable.replace(0, variable.length(), newValue) println("Lock with id:$tmpID is changed to $newValue!") sendEvent([name: "lock", value: newValue, deviceId: tmpID, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) } } // Methods to return values def getCurrentLock() { return currentLock.toString() } }