X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=RelaySwitch%2FRelaySwitch.groovy;h=059ebaee3dc883da1401f35ed75d94a1b4cda537;hb=2d26e7af07daad1394408bdcf76150b5aacf3a8a;hp=82fdc4ca340ff60a9ef9309ccdfbc5b6b07b505b;hpb=83071d3bcfc33f015ece13868342644498a9dda3;p=smartthings-infrastructure.git diff --git a/RelaySwitch/RelaySwitch.groovy b/RelaySwitch/RelaySwitch.groovy index 82fdc4c..059ebae 100644 --- a/RelaySwitch/RelaySwitch.groovy +++ b/RelaySwitch/RelaySwitch.groovy @@ -4,16 +4,14 @@ import SmartThing.SmartThing public class RelaySwitch 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 currentSwitch = new StringBuilder() + String id + String label + String displayName // Maps from features to values - HashMap deviceValuesMap = new HashMap() + HashMap deviceValuesMap = new HashMap() - RelaySwitch(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentSwitch) { - deviceValuesMap = deviceValueSmartThing + RelaySwitch(Closure sendEvent, String id, String label, String displayName, String currentSwitch) { + deviceValueSmartThing = deviceValuesMap idSmartThing = id labelSmartThing = label displayNameSmartThing = displayName @@ -23,14 +21,13 @@ public class RelaySwitch extends SmartThing { this.id = id this.label = label this.displayName = displayName - this.currentSwitch = currentSwitch deviceValuesMap.put("switch", currentSwitch) } // Methods to set values def on() { - action(currentSwitch, "on", "switch") + action("on", "switch") } def on(LinkedHashMap metaData) { @@ -38,25 +35,10 @@ public class RelaySwitch extends SmartThing { } def off() { - action(currentSwitch, "off", "switch") + action("off", "switch") } def off(LinkedHashMap metaData) { off() } - - 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 relay switch 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 getCurrentSwitch() { - return currentSwitch.toString() - } }