1 //Create a class for door control device
3 import SmartThing.SmartThing
5 public class DoorControl 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 currentDoorState = new StringBuilder()
12 // Maps from features to values
13 HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
15 DoorControl(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentDoorState) {
16 deviceValuesMap = deviceValueSmartThing
18 labelSmartThing = label
19 displayNameSmartThing = displayName
20 sendEventSmartThings = sendEvent
25 this.displayName = displayName
26 this.currentDoorState = currentDoorState
28 deviceValuesMap.put("status", currentDoorState)
31 // Methods to set values
33 action(currentDoorState, "open", "status")
36 def open(LinkedHashMap metaData) {
41 action(currentDoorState, "closed", "status")
44 def close(LinkedHashMap metaData) {
48 def action(StringBuilder variable, String newValue, String feature) {
49 if (!variable.toString().equals(newValue)) {
50 String tmpID = id.toString()
51 variable.replace(0, variable.length(), newValue)
52 println("$feature of the door with id:$tmpID is changed to $newValue!")
53 sendEvent([name: feature, value: newValue, deviceId: tmpID, descriptionText: "",
54 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
58 // Methods to return values
59 def getCurrentDoorState() {
60 return currentDoorState.toString()