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"}'])
81 def off(String currentSwitch) {
82 if (currentSwitch != this.currentSwitch) {
83 this.currentSwitch = currentSwitch
84 println("The light is changed to $currentSwitch!")
85 sendEvent([name: "switch", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
86 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
90 def currentValue(String deviceFeature) {
91 if (deviceFeature == "level") {
93 } else if (deviceFeature == "colorTemperature") {
94 return colorTemperature
95 } else if (deviceFeature == "switch") {
100 def latestValue(String deviceFeature) {
101 if (deviceFeature == "level") {
103 } else if (deviceFeature == "colorTemperature") {
104 return colorTemperature
105 } else if (deviceFeature == "switch") {