Commit #10: more classes
[smartthings-infrastructure.git] / ColorControl / ColorControl.groovy
1 //Create a class for color control
2 package ColorControl
3 import Timer.SimulatedTimer
4
5
6 public class ColorControl {
7         private String id
8         private String label
9         private String displayName
10         private String color
11         private int hue
12         private int saturation
13         
14         ColorControl(String id, String label, String displayName, String color, int hue, int saturation) {
15                 this.id = id
16                 this.label = label
17                 this.displayName = displayName
18                 this.color = color
19                 this.hue = hue
20                 this.saturation = saturation
21         }
22         
23         //By model checker
24         def setValue(String value, String name) {
25                 if (name == "color") {
26                         this.color = value
27                         println("the color of the light is changed to $value!")
28                 } else if (name == "hue") {
29                         this.hue = value.toInteger()
30                         println("The hue level of the light is changed to $value!")
31                 } else {
32                         this.saturation = value.toInteger()
33                         println("The saturation level of the light is changed to $value!")
34                 }
35         }
36
37         //methods
38         def setColor(String color) {
39                 this.color = color
40                 println("The color of the light is changed to $color!")
41                 sendEvent([name: "color", value: "$color", deviceId: this.id, descriptionText: "",
42                            displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "$color"]]) 
43         }
44
45         def setHue(int hue) {
46                 this.hue = hue
47                 println("The hue level of the light is changed to $hue!")
48                 sendEvent([name: "hue", value: "$hue", deviceId: this.id, descriptionText: "",
49                            displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "$hue"]]) 
50         }
51
52         def setSaturation(int saturation) {
53                 this.saturation = saturation
54                 println("The saturation level of the light is changed to $saturation!")
55                 sendEvent([name: "saturation", value: "$saturation", deviceId: this.id, descriptionText: "",
56                            displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "$saturation"]]) 
57         }
58
59         def currentValue(String deviceFeature) {
60                 if (deviceFeature == "color") {
61                         return color
62                 } else if (deviceFeature == "saturation") {
63                         return saturation
64                 } else if (deviceFeature == "hue") {
65                         return hue
66                 }
67         }
68 }