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
- 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
- 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
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)
// Methods to set values
def setColor(String newValue) {
- action(currentColor, newValue, "color")
+ action(newValue, "color")
}
def setHue(int newValue) {
- action(currentHue, newValue, "hue")
+ action(newValue, "hue")
}
def setHue(double newValue) {
}
def setSaturation(int newValue) {
- action(currentSaturation, newValue, "saturation")
+ action(newValue, "saturation")
}
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()
- }
}