Infrastructure that works for all the locks' group!
[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") && (value != this.color)) {
26                         this.color = value
27                         println("the color of the light is changed to $value!")
28                 } else if ((name == "hue") && (value != this.hue)) {
29                         this.hue = value.toInteger()
30                         println("The hue level of the light is changed to $value!")
31                 } else if (value != this.saturation) {
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                 if (color != this.color) {
40                         this.color = color
41                         println("The color of the light is changed to $color!")
42                         sendEvent([name: "color", value: "$color", deviceId: this.id, descriptionText: "",
43                                    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
44                 }
45         }
46
47         def setHue(int hue) {
48                 if (hue != this.hue) {
49                         this.hue = hue
50                         println("The hue level of the light is changed to $hue!")
51                         sendEvent([name: "hue", value: "$hue", deviceId: this.id, descriptionText: "",
52                                    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
53                 }
54         }
55
56         def setSaturation(int saturation) {
57                 if (saturation != this.saturation) {
58                         this.saturation = saturation
59                         println("The saturation level of the light is changed to $saturation!")
60                         sendEvent([name: "saturation", value: "$saturation", deviceId: this.id, descriptionText: "",
61                                    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
62                 }
63         }
64
65         def currentValue(String deviceFeature) {
66                 if (deviceFeature == "color") {
67                         return color
68                 } else if (deviceFeature == "saturation") {
69                         return saturation
70                 } else if (deviceFeature == "hue") {
71                         return hue
72                 }
73         }
74 }