X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=Valve%2FValve.groovy;h=91eef557b8bcb0084413c15b7a541a5011035ea2;hb=2d26e7af07daad1394408bdcf76150b5aacf3a8a;hp=0cd43a9fe7b415725226e732dd755782de9fad17;hpb=83071d3bcfc33f015ece13868342644498a9dda3;p=smartthings-infrastructure.git diff --git a/Valve/Valve.groovy b/Valve/Valve.groovy index 0cd43a9..91eef55 100644 --- a/Valve/Valve.groovy +++ b/Valve/Valve.groovy @@ -4,16 +4,14 @@ import SmartThing.SmartThing public class Valve 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 currentValve = new StringBuilder() + String id + String label + String displayName // Maps from features to values - HashMap deviceValuesMap = new HashMap() + HashMap deviceValuesMap = new HashMap() - Valve(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentValve) { - deviceValuesMap = deviceValueSmartThing + Valve(Closure sendEvent, String id, String label, String displayName, String currentValve) { + deviceValueSmartThing = deviceValuesMap idSmartThing = id labelSmartThing = label displayNameSmartThing = displayName @@ -23,14 +21,13 @@ public class Valve extends SmartThing { this.id = id this.label = label this.displayName = displayName - this.currentValve = currentValve - deviceValuesMap.put("valve", currentValve) + deviceValuesMap.put("contact", currentContact) } // Methods to set values def open() { - action(currentValve, "open", "contact") + action("open", "contact") } def open(LinkedHashMap metaData) { @@ -38,25 +35,10 @@ public class Valve extends SmartThing { } def close() { - action(currentValve, "closed", "contact") + action("closed", "contact") } 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 valve with id:$tmpID is $newValue!") - sendEvent([name: feature, value: newValue, deviceId: tmpID, descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) - } - } - - // Methods to return values - def getCurrentValve() { - return currentValve.toString() - } }