1 //Create a class for color control
3 import Timer.SimulatedTimer
6 public class ColorControl {
10 private String displayName
12 private String currentSwitch
15 private int saturation
16 private int colorTemperature
18 ColorControl(Closure sendEvent, String id, String label, String displayName, String color, int hue, int saturation, int level, String currentSwitch, int colorTemperature) {
21 this.displayName = displayName
24 this.saturation = saturation
26 this.currentSwitch = currentSwitch
27 this.colorTemperature = colorTemperature
28 this.sendEvent = sendEvent
32 def setValue(String value, String name) {
33 if ((name == "color") && (value != this.color)) {
35 println("the color of the light is changed to $value!")
36 } else if ((name == "hue") && (value != this.hue)) {
37 this.hue = value.toInteger()
38 println("The hue level of the light is changed to $value!")
39 } else if ((name == "saturation") && (value != this.saturation)) {
40 this.saturation = value.toInteger()
41 println("The saturation level of the light is changed to $value!")
42 } else if ((name == "level") && (value != this.level)) {
43 this.level = value.toInteger()
44 println("The level of the light is changed to $value!")
45 } else if ((name == "currentSwitch") && (value != this.currentSwitch)) {
46 this.currentSwitch = value
47 println("The light is changed to $value!")
48 } else if ((name == "colorTemperature") && (value != this.colorTemperature)) {
49 this.colorTemperature = value.toInteger()
50 println("The color temperature level of the light is changed to $value!")
55 def setColor(String color) {
56 if (color != this.color) {
58 println("The color of the light is changed to $color!")
59 sendEvent([name: "color", value: "$color", deviceId: this.id, descriptionText: "",
60 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
65 if (hue != this.hue) {
67 println("The hue level of the light is changed to $hue!")
68 sendEvent([name: "hue", value: "$hue", deviceId: this.id, descriptionText: "",
69 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
73 def setSaturation(int saturation) {
74 if (saturation != this.saturation) {
75 this.saturation = saturation
76 println("The saturation level of the light is changed to $saturation!")
77 sendEvent([name: "saturation", value: "$saturation", deviceId: this.id, descriptionText: "",
78 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
82 def setLevel(int level) {
83 if (level != this.level) {
85 println("The level of the light is changed to $level!")
86 sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
87 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
91 def setColorTemperature(int colorTemperature) {
92 if (colorTemperature != this.colorTemperature) {
93 this.colorTemperature = colorTemperature
94 println("The color temperature level of the light is changed to $colorTemperature!")
95 sendEvent([name: "colorTemperature", value: "$colorTemperature", deviceId: this.id, descriptionText: "",
96 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
100 def on(String currentSwitch) {
101 if (currentSwitch != this.currentSwitch) {
102 this.currentSwitch = currentSwitch
103 println("The light is changed to $currentSwitch!")
104 sendEvent([name: "switch", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
105 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
106 sendEvent([name: "switch.on", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
107 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
111 def off(String currentSwitch) {
112 if (currentSwitch != this.currentSwitch) {
113 this.currentSwitch = currentSwitch
114 println("The light is changed to $currentSwitch!")
115 sendEvent([name: "switch", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
116 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
117 sendEvent([name: "switch.off", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
118 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
122 def currentValue(String deviceFeature) {
123 if (deviceFeature == "color") {
125 } else if (deviceFeature == "saturation") {
127 } else if (deviceFeature == "hue") {
129 } else if (deviceFeature == "level") {
131 } else if (deviceFeature == "colorTemperature") {
132 return colorTemperature
133 } else if (deviceFeature == "switch") {
138 def latestValue(String deviceFeature) {
139 if (deviceFeature == "color") {
141 } else if (deviceFeature == "saturation") {
143 } else if (deviceFeature == "hue") {
145 } else if (deviceFeature == "level") {
147 } else if (deviceFeature == "colorTemperature") {
148 return colorTemperature
149 } else if (deviceFeature == "switch") {