1 //Create a class for color control
3 import Timer.SimulatedTimer
6 public class ColorControl {
9 private String displayName
11 private String currentSwitch
14 private int saturation
15 private int colorTemperature
17 ColorControl(String id, String label, String displayName, String color, int hue, int saturation, int level, String currentSwitch, int colorTemperature) {
20 this.displayName = displayName
23 this.saturation = saturation
25 this.currentSwitch = currentSwitch
26 this.colorTemperature = colorTemperature
30 def setValue(String value, String name) {
31 if ((name == "color") && (value != this.color)) {
33 println("the color of the light is changed to $value!")
34 } else if ((name == "hue") && (value != this.hue)) {
35 this.hue = value.toInteger()
36 println("The hue level of the light is changed to $value!")
37 } else if ((name == "saturation") && (value != this.saturation)) {
38 this.saturation = value.toInteger()
39 println("The saturation level of the light is changed to $value!")
40 } else if ((name == "level") && (value != this.level)) {
41 this.level = value.toInteger()
42 println("The level of the light is changed to $value!")
43 } else if ((name == "currentSwitch") && (value != this.currentSwitch)) {
44 this.currentSwitch = value
45 println("The light is changed to $value!")
46 } else if ((name == "colorTemperature") && (value != this.colorTemperature)) {
47 this.colorTemperature = value.toInteger()
48 println("The color temperature level of the light is changed to $value!")
53 def setColor(String color) {
54 if (color != this.color) {
56 println("The color of the light is changed to $color!")
57 sendEvent([name: "color", value: "$color", deviceId: this.id, descriptionText: "",
58 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
63 if (hue != this.hue) {
65 println("The hue level of the light is changed to $hue!")
66 sendEvent([name: "hue", value: "$hue", deviceId: this.id, descriptionText: "",
67 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
71 def setSaturation(int saturation) {
72 if (saturation != this.saturation) {
73 this.saturation = saturation
74 println("The saturation level of the light is changed to $saturation!")
75 sendEvent([name: "saturation", value: "$saturation", deviceId: this.id, descriptionText: "",
76 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
80 def setLevel(int level) {
81 if (level != this.level) {
83 println("The level of the light is changed to $level!")
84 sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
85 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
89 def setColorTemperature(int colorTemperature) {
90 if (colorTemperature != this.colorTemperature) {
91 this.colorTemperature = colorTemperature
92 println("The color temperature level of the light is changed to $colorTemperature!")
93 sendEvent([name: "colorTemperature", value: "$colorTemperature", deviceId: this.id, descriptionText: "",
94 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
98 def on(String currentSwitch) {
99 if (currentSwitch != this.currentSwitch) {
100 this.currentSwitch = currentSwitch
101 println("The light is changed to $currentSwitch!")
102 sendEvent([name: "switch", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
103 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
104 sendEvent([name: "switch.on", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
105 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
109 def off(String currentSwitch) {
110 if (currentSwitch != this.currentSwitch) {
111 this.currentSwitch = currentSwitch
112 println("The light is changed to $currentSwitch!")
113 sendEvent([name: "switch", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
114 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
115 sendEvent([name: "switch.off", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
116 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
120 def currentValue(String deviceFeature) {
121 if (deviceFeature == "color") {
123 } else if (deviceFeature == "saturation") {
125 } else if (deviceFeature == "hue") {
127 } else if (deviceFeature == "level") {
129 } else if (deviceFeature == "colorTemperature") {
130 return colorTemperature
131 } else if (deviceFeature == "switch") {
136 def latestValue(String deviceFeature) {
137 if (deviceFeature == "color") {
139 } else if (deviceFeature == "saturation") {
141 } else if (deviceFeature == "hue") {
143 } else if (deviceFeature == "level") {
145 } else if (deviceFeature == "colorTemperature") {
146 return colorTemperature
147 } else if (deviceFeature == "switch") {