1 //Create a class for color temperature
2 package ColorTemperature
3 import Timer.SimulatedTimer
6 public class ColorTemperature {
10 private String displayName
11 private String currentSwitch
13 private int currentLevel
14 private int colorTemperature
16 ColorTemperature(Closure sendEvent, String id, String label, String displayName, int level, String currentSwitch, int colorTemperature) {
19 this.displayName = displayName
21 this.currentLevel = level
22 this.currentSwitch = currentSwitch
23 this.colorTemperature = colorTemperature
24 this.sendEvent = sendEvent
28 def setValue(String value, String name) {
29 if ((name == "level") && (value != this.level)) {
30 this.currentLevel = value.toInteger()
31 this.level = value.toInteger()
32 println("The level of the light is changed to $value!")
33 } else if ((name == "currentSwitch") && (value != this.currentSwitch)) {
34 this.currentSwitch = value
35 println("The light is changed to $value!")
36 } else if ((name == "colorTemperature") && (value != this.colorTemperature)) {
37 this.colorTemperature = value.toInteger()
38 println("The color temperature level of the light is changed to $value!")
43 def setLevel(int level) {
44 if (level != this.level) {
45 this.currentLevel = level
47 println("The level of the light is changed to $level!")
48 sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
49 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
53 def setColorTemperature(int colorTemperature) {
54 if (colorTemperature != this.colorTemperature) {
55 this.colorTemperature = colorTemperature
56 println("The color temperature level of the light is changed to $colorTemperature!")
57 sendEvent([name: "colorTemperature", value: "$colorTemperature", deviceId: this.id, descriptionText: "",
58 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
62 def on(String currentSwitch) {
63 if (currentSwitch != this.currentSwitch) {
64 this.currentSwitch = currentSwitch
65 println("The light is changed to $currentSwitch!")
66 sendEvent([name: "switch", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
67 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
68 sendEvent([name: "switch.on", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
69 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
73 def off(String currentSwitch) {
74 if (currentSwitch != this.currentSwitch) {
75 this.currentSwitch = currentSwitch
76 println("The light is changed to $currentSwitch!")
77 sendEvent([name: "switch", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
78 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
79 sendEvent([name: "switch.off", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
80 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
84 def currentValue(String deviceFeature) {
85 if (deviceFeature == "level") {
87 } else if (deviceFeature == "colorTemperature") {
88 return colorTemperature
89 } else if (deviceFeature == "switch") {
94 def latestValue(String deviceFeature) {
95 if (deviceFeature == "level") {
97 } else if (deviceFeature == "colorTemperature") {
98 return colorTemperature
99 } else if (deviceFeature == "switch") {