public class DoorControl 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 currentDoorState = new StringBuilder()
+ String id
+ String label
+ String displayName
// Maps from features to values
- HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+ HashMap<String, String> deviceValuesMap = new HashMap<String, String>()
- DoorControl(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentDoorState) {
- deviceValuesMap = deviceValueSmartThing
+ DoorControl(Closure sendEvent, String id, String label, String displayName, String currentDoor) {
+ deviceValueSmartThing = deviceValuesMap
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
this.id = id
this.label = label
this.displayName = displayName
- this.currentDoorState = currentDoorState
- deviceValuesMap.put("status", currentDoorState)
+ deviceValuesMap.put("door", currentDoor)
}
// Methods to set values
def open() {
- action(currentDoorState, "open", "status")
+ action("open", "door")
}
def open(LinkedHashMap metaData) {
}
def close() {
- action(currentDoorState, "closed", "status")
+ action("closed", "door")
}
def close(LinkedHashMap metaData) {
close()
}
-
- def action(StringBuilder variable, String newValue, String feature) {
- if (!variable.toString().equals(newValue)) {
- String tmpID = id.toString()
- variable.replace(0, variable.length(), newValue)
- println("$feature of the door with id:$tmpID is changed to $newValue!")
- sendEvent([name: feature, value: newValue, deviceId: tmpID, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
- }
-
- // Methods to return values
- def getCurrentDoorState() {
- return currentDoorState.toString()
- }
}