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