087ee8a0405565a65b498b07cb5b894d5a156b1c
[smartthings-infrastructure.git] / ColorTemperature / ColorTemperature.groovy
1 //Create a class for color temperature
2 package ColorTemperature
3 import SmartThing.SmartThing
4
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>()
14
15         ColorTemperature(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, MutableInteger colorTemperature) {
16                 deviceIntValuesMap = deviceIntValueSmartThing
17                 idSmartThing = id
18                 labelSmartThing = label
19                 displayNameSmartThing = displayName
20                 sendEventSmartThings = sendEvent
21
22                 // Initialization
23                 this.id = id
24                 this.label = label
25                 this.displayName = displayName
26                 this.currentColorTemperature = currentColorTemperature
27
28                 deviceIntValuesMap.put("colorTemperature", currentColorTemperature)
29         }
30
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"}'])
39                 }
40         }
41
42         // Methods to return values
43         def getCurrentColorTemperature() {
44                 return currentColorTemperature.getValue()
45         }
46 }