Removing getXXX methods + properties. Adding getProperty feature to SmartThing(s)
[smartthings-infrastructure.git] / ColorControl / ColorControl.groovy
index c278f4ae3a8fb6d73c50cee473c867b3df713058..4380f24408c0c5534d994ae06440b5625101a79c 100644 (file)
@@ -2,26 +2,18 @@
 package ColorControl
 import SmartThing.SmartThing
 
 package ColorControl
 import SmartThing.SmartThing
 
-//Importing mutable integer class
-import MutableInteger.MutableInteger
-
 public class ColorControl extends SmartThing {
        // id, label, and display name of the device
 public class ColorControl extends SmartThing {
        // id, label, and display name of the device
-       StringBuilder id = new StringBuilder()
-       StringBuilder label = new StringBuilder()
-       StringBuilder displayName = new StringBuilder()
-       // Features with numberical values
-       MutableInteger currentHue = new MutableInteger()
-       MutableInteger currentSaturation = new MutableInteger()
-       // Features with string values
-       StringBuilder currentColor = new StringBuilder()
+       String id
+       String label
+       String displayName
        // Maps from features to values
        // Maps from features to values
-       HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
-       HashMap<String, MutableInteger> deviceIntValuesMap = new HashMap<String, MutableInteger>()
+       HashMap<String, String> deviceValuesMap = new HashMap<String, String>()
+       HashMap<String, Integer> deviceIntValuesMap = new HashMap<String, Integer>()
 
 
-       ColorControl(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentColor, MutableInteger currentHue, MutableInteger currentSaturation) {
-               deviceValuesMap = deviceValueSmartThing
-               deviceIntValuesMap = deviceIntValueSmartThing
+       ColorControl(Closure sendEvent, String id, String label, String displayName, String currentColor, Integer currentHue, Integer currentSaturation) {
+               deviceValueSmartThing = deviceValuesMap
+               deviceIntValueSmartThing = deviceIntValuesMap
                idSmartThing = id
                labelSmartThing = label
                displayNameSmartThing = displayName
                idSmartThing = id
                labelSmartThing = label
                displayNameSmartThing = displayName
@@ -31,9 +23,6 @@ public class ColorControl extends SmartThing {
                this.id = id
                this.label = label
                this.displayName = displayName
                this.id = id
                this.label = label
                this.displayName = displayName
-               this.currentHue = currentHue
-               this.currentSaturation = currentSaturation
-               this.currentColor = currentColor
 
                deviceValuesMap.put("color", currentColor)
                deviceIntValuesMap.put("hue", currentHue)
 
                deviceValuesMap.put("color", currentColor)
                deviceIntValuesMap.put("hue", currentHue)
@@ -74,11 +63,11 @@ public class ColorControl extends SmartThing {
 
        // Methods to set values
        def setColor(String newValue) {
 
        // Methods to set values
        def setColor(String newValue) {
-               action(currentColor, newValue, "color")
+               action(newValue, "color")
        }
 
        def setHue(int newValue) {
        }
 
        def setHue(int newValue) {
-               action(currentHue, newValue, "hue")
+               action(newValue, "hue")
        }
        
        def setHue(double newValue) {
        }
        
        def setHue(double newValue) {
@@ -86,43 +75,10 @@ public class ColorControl extends SmartThing {
        }
 
        def setSaturation(int newValue) {
        }
 
        def setSaturation(int newValue) {
-               action(currentSaturation, newValue, "saturation")
+               action(newValue, "saturation")
        }
        
        def setSaturation(double newValue) {
                setSaturation((int) newValue)
        }
        }
        
        def setSaturation(double newValue) {
                setSaturation((int) newValue)
        }
-
-       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:$id is changed to $newValue!")
-                       sendEvent([name: feature, value: newValue, deviceId: tmpID, descriptionText: "",
-                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
-       }
-
-       def action(MutableInteger variable, int newValue, String feature) {
-               if (!variable.getValue().equals(newValue)) {
-                       String tmpID = id.toString()
-                       variable.setValue(newValue)
-                       println("$feature of the light with id:$id 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 getCurrentHue() {
-               return currentHue.getValue()
-       }
-
-       def getCurrentSaturation() {
-               return currentSaturation.getValue()
-       }
-       
-       def getCurrentColor() {
-               return currentColor.toString()
-       }
 }
 }