adac0b8e82c12980af1ab7e684e456dabbb420ef
[smartthings-infrastructure.git] / ColorControl / ColorControls.groovy
1 //Create a class for color control
2 package ColorControl
3 import SmartThing.SmartThings
4
5 public class ColorControls extends SmartThings {
6         List colorControls = new ArrayList()
7         
8         ColorControls(Closure sendEvent, boolean init) {
9                 // Only initialize one time since we only have one device for each capability
10                 colorControls = smartThings
11
12                 // Initialization
13                 StringBuilder id = new StringBuilder("colorControlID0")
14                 StringBuilder label = new StringBuilder("colorControl")
15                 StringBuilder displayName = new StringBuilder("colorControl0")
16                 StringBuilder color = new StringBuilder()
17                 MutableInteger hue = new MutableInteger()
18                 MutableInteger saturation = new MutableInteger()
19
20                 if (init) {
21                         color.append("Red")
22                         hue.setValue(30)
23                         saturation.setValue(40)
24                 } else {                
25                         color.append("Blue")
26                         hue.setValue(50)
27                         saturation.setValue(50)
28                 }
29
30                 colorControls.add(new ColorControl(sendEvent, id, label, displayName, color, hue,
31                                                    saturation))
32         }
33
34         // Methods to set values
35         def setColor(LinkedHashMap metaData) {
36                 colorControls[0].setColor(metaData)
37         }
38
39         def setColor(String color) {
40                 colorControls[0].setColor(color)
41         }
42
43         def setHue(int hue) {
44                 colorControls[0].setHue(hue)
45         }
46         
47         def setHue(double hue) {
48                 colorControls[0].setHue((int) hue)
49         }
50
51         def setSaturation(int saturation) {
52                 colorControls[0].setSaturation(saturation)      
53         }
54         
55         def setSaturation(double saturation) {
56                 colorControls[0].setSaturation((int) saturation)
57         }
58
59         def on() {
60                 colorControls[0].on()
61         }
62
63         def off() {
64                 colorControls[0].off()
65         }
66
67         // Methods to return values
68         def getCurrentHue() {
69                 List tmpValues = new ArrayList()
70                 tmpValues.add(colorControls[0].getCurrentHue())
71                 return tmpValues
72         }
73
74         def getCurrentSaturation() {
75                 List tmpValues = new ArrayList()
76                 tmpValues.add(colorControls[0].getCurrentSaturation())
77                 return tmpValues
78         }
79         
80         def getCurrentColor() {
81                 List tmpValues = new ArrayList()
82                 tmpValues.add(colorControls[0].getCurrentColor())
83                 return tmpValues
84         }
85 }