1 //Create a class for color temperature
2 package ColorTemperature
3 import SmartThing.SmartThing
5 public class ColorTemperature extends SmartThing {
6 // id, label, and display name of the device
7 StringBuilder id = new StringBuilder()
8 StringBuilder label = new StringBuilder()
9 StringBuilder displayName = new StringBuilder()
10 // Features with numberical values
11 MutableInteger currentColorTemperature = new MutableInteger()
12 // Maps from features to values
13 HashMap<String, MutableInteger> deviceIntValuesMap = new HashMap<String, MutableInteger>()
15 ColorTemperature(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, MutableInteger colorTemperature) {
16 deviceIntValuesMap = deviceIntValueSmartThing
18 labelSmartThing = label
19 displayNameSmartThing = displayName
20 sendEventSmartThings = sendEvent
25 this.displayName = displayName
26 this.currentColorTemperature = currentColorTemperature
28 deviceIntValuesMap.put("colorTemperature", currentColorTemperature)
31 // Methods to set values
32 def setColorTemperature(int newValue) {
33 if (!currentColorTemperature.getValue().equals(newValue)) {
34 String tmpID = id.toString()
35 currentColorTemperature.setValue(newValue)
36 println("The color temperature of the light with id $tmpID is changed to $newValue!")
37 sendEvent([name: "colorTemperature", value: "$newValue", deviceId: tmpID, descriptionText: "",
38 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
42 // Methods to return values
43 def getCurrentColorTemperature() {
44 return currentColorTemperature.getValue()