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 setLevel(long level) {
54 if (level != this.level) {
55 this.currentLevel = level
57 println("The level of the light is changed to $level!")
58 sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
59 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
63 def setColorTemperature(int colorTemperature) {
64 if (colorTemperature != this.colorTemperature) {
65 this.colorTemperature = colorTemperature
66 println("The color temperature level of the light is changed to $colorTemperature!")
67 sendEvent([name: "colorTemperature", value: "$colorTemperature", deviceId: this.id, descriptionText: "",
68 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
72 def on(String currentSwitch) {
73 if (currentSwitch != this.currentSwitch) {
74 this.currentSwitch = currentSwitch
75 println("The light is changed to $currentSwitch!")
76 sendEvent([name: "switch", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
77 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
78 sendEvent([name: "switch.on", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
79 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
83 def off(String currentSwitch) {
84 if (currentSwitch != this.currentSwitch) {
85 this.currentSwitch = currentSwitch
86 println("The light is changed to $currentSwitch!")
87 sendEvent([name: "switch", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
88 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
89 sendEvent([name: "switch.off", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
90 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
94 def currentValue(String deviceFeature) {
95 if (deviceFeature == "level") {
97 } else if (deviceFeature == "colorTemperature") {
98 return colorTemperature
99 } else if (deviceFeature == "switch") {
104 def latestValue(String deviceFeature) {
105 if (deviceFeature == "level") {
107 } else if (deviceFeature == "colorTemperature") {
108 return colorTemperature
109 } else if (deviceFeature == "switch") {