1 //Create a class for color control
3 import Timer.SimulatedTimer
6 public class ColorControl {
9 private String displayName
12 private int saturation
14 ColorControl(String id, String label, String displayName, String color, int hue, int saturation) {
17 this.displayName = displayName
20 this.saturation = saturation
24 def setValue(String value, String name) {
25 if ((name == "color") && (value != this.color)) {
27 println("the color of the light is changed to $value!")
28 } else if ((name == "hue") && (value != this.hue)) {
29 this.hue = value.toInteger()
30 println("The hue level of the light is changed to $value!")
31 } else if (value != this.saturation) {
32 this.saturation = value.toInteger()
33 println("The saturation level of the light is changed to $value!")
38 def setColor(String color) {
39 if (color != this.color) {
41 println("The color of the light is changed to $color!")
42 sendEvent([name: "color", value: "$color", deviceId: this.id, descriptionText: "",
43 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
48 if (hue != this.hue) {
50 println("The hue level of the light is changed to $hue!")
51 sendEvent([name: "hue", value: "$hue", deviceId: this.id, descriptionText: "",
52 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
56 def setSaturation(int saturation) {
57 if (saturation != this.saturation) {
58 this.saturation = saturation
59 println("The saturation level of the light is changed to $saturation!")
60 sendEvent([name: "saturation", value: "$saturation", deviceId: this.id, descriptionText: "",
61 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
65 def currentValue(String deviceFeature) {
66 if (deviceFeature == "color") {
68 } else if (deviceFeature == "saturation") {
70 } else if (deviceFeature == "hue") {