X-Git-Url: http://plrg.eecs.uci.edu/git/?p=smartthings-infrastructure.git;a=blobdiff_plain;f=DoorControl%2FDoorControl.groovy;h=a72e5f7c126a20a622759526bebec9ed5c491994;hp=d0027273b4260ab0e18e27f22070ca050a722dd0;hb=2d26e7af07daad1394408bdcf76150b5aacf3a8a;hpb=83071d3bcfc33f015ece13868342644498a9dda3 diff --git a/DoorControl/DoorControl.groovy b/DoorControl/DoorControl.groovy index d002727..a72e5f7 100644 --- a/DoorControl/DoorControl.groovy +++ b/DoorControl/DoorControl.groovy @@ -4,16 +4,14 @@ import SmartThing.SmartThing 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 deviceValuesMap = new HashMap() + HashMap deviceValuesMap = new HashMap() - 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 @@ -23,14 +21,13 @@ public class DoorControl extends SmartThing { 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) { @@ -38,25 +35,10 @@ public class DoorControl extends SmartThing { } 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() - } }