//Create a class for color control package ColorControl import SmartThing.SmartThing public class ColorControl extends SmartThing { // id, label, and display name of the device String id String label String displayName // Maps from features to values HashMap deviceValuesMap = new HashMap() HashMap deviceIntValuesMap = new HashMap() 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 sendEventSmartThings = sendEvent // Initialization this.id = id this.label = label this.displayName = displayName deviceValuesMap.put("color", currentColor) deviceIntValuesMap.put("hue", currentHue) deviceIntValuesMap.put("saturation", currentSaturation) } def setColor(LinkedHashMap metaData) { def hexColor = metaData.hex def newColor switch (hexColor) { case "#0000FF": newColor = "Blue" break; case "#00FF00": newColor = "Green" break; case "#FFFF00": newColor = "Yellow" break; case "#FF6000": newColor = "Orange" break; case "#BF7FBF": newColor = "Purple" break; case "#FF5F5F": newColor = "Pink" break; case "#FF0000": newColor = "Red" break; default: newColor = "Blue" break; } setColor(newColor) } // Methods to set values def setColor(String newValue) { action(newValue, "color") } def setHue(int newValue) { action(newValue, "hue") } def setHue(double newValue) { setHue((int) newValue) } def setSaturation(int newValue) { action(newValue, "saturation") } def setSaturation(double newValue) { setSaturation((int) newValue) } }