Fixing bug in Mobile Presence class
[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                 String id = "colorControlID0"
14                 String label = "colorControl"
15                 String displayName = "light"
16                 String color
17                 Integer hue
18                 Integer saturation
19
20                 if (init) {
21                         color = "Red"
22                         hue = 30
23                         saturation = 40
24                 } else {                
25                         color = "Blue"
26                         hue = 50
27                         saturation = 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 }