Removing getXXX methods + properties. Adding getProperty feature to SmartThing(s)
[smartthings-infrastructure.git] / Switch / Switch.groovy
index b95bca122f2d69127e43079c8956e1eb38aabc75..d44846c9181ace4c04edba9c5e7ed243cfde3adb 100644 (file)
@@ -4,18 +4,16 @@ import SmartThing.SmartThing
 
 public class Switch 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>()
        // Possible values for eventsSince method
-       List<StringBuilder> possibleValues = new ArrayList<StringBuilder>();
+       List<String> possibleValues = new ArrayList<String>();
 
-       Switch(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentSwitch) {
-               deviceValuesMap = deviceValueSmartThing
+       Switch(Closure sendEvent, String id, String label, String displayName, String currentSwitch) {
+               deviceValueSmartThing = deviceValuesMap
                idSmartThing = id
                labelSmartThing = label
                displayNameSmartThing = displayName
@@ -26,7 +24,6 @@ public class Switch extends SmartThing {
                this.id = id
                this.label = label
                this.displayName = displayName
-               this.currentSwitch = currentSwitch
                possibleValues.add("on")
                possibleValues.add("off")
 
@@ -35,7 +32,7 @@ public class Switch extends SmartThing {
 
        // Methods to set values
        def on() {
-               action(currentSwitch, "on", "switch")
+               action("on", "switch")
        }
 
        def on(LinkedHashMap metaData) {
@@ -43,25 +40,10 @@ public class Switch 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 light 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()
-       }
 }