Removing getXXX methods + properties. Adding getProperty feature to SmartThing(s)
[smartthings-infrastructure.git] / RelaySwitch / RelaySwitch.groovy
index 82fdc4ca340ff60a9ef9309ccdfbc5b6b07b505b..059ebaee3dc883da1401f35ed75d94a1b4cda537 100644 (file)
@@ -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<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+       HashMap<String, String> deviceValuesMap = new HashMap<String, String>()
 
-       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()
-       }
 }