Fixing app list for Alarms 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 String currentSwitch
12         private int level
13         private int hue
14         private int saturation
15         private int colorTemperature
16         
17         ColorControl(String id, String label, String displayName, String color, int hue, int saturation, int level, String currentSwitch, int colorTemperature) {
18                 this.id = id
19                 this.label = label
20                 this.displayName = displayName
21                 this.color = color
22                 this.hue = hue
23                 this.saturation = saturation
24                 this.level = level
25                 this.currentSwitch = currentSwitch
26                 this.colorTemperature = colorTemperature
27         }
28         
29         //By model checker
30         def setValue(String value, String name) {
31                 if ((name == "color") && (value != this.color)) {
32                         this.color = value
33                         println("the color of the light is changed to $value!")
34                 } else if ((name == "hue") && (value != this.hue)) {
35                         this.hue = value.toInteger()
36                         println("The hue level of the light is changed to $value!")
37                 } else if ((name == "saturation") && (value != this.saturation)) {
38                         this.saturation = value.toInteger()
39                         println("The saturation level of the light is changed to $value!")
40                 } else if ((name == "level") && (value != this.level)) {
41                         this.level = value.toInteger()
42                         println("The level of the light is changed to $value!")
43                 } else if ((name == "currentSwitch") && (value != this.currentSwitch)) {
44                         this.currentSwitch = value
45                         println("The light is changed to $value!")
46                 } else if ((name == "colorTemperature") && (value != this.colorTemperature)) {
47                         this.colorTemperature = value.toInteger()
48                         println("The color temperature level of the light is changed to $value!")
49                 }
50         }
51
52         //methods
53         def setColor(String color) {
54                 if (color != this.color) {
55                         this.color = color
56                         println("The color of the light is changed to $color!")
57                         sendEvent([name: "color", value: "$color", deviceId: this.id, descriptionText: "",
58                                    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
59                 }
60         }
61
62         def setHue(int hue) {
63                 if (hue != this.hue) {
64                         this.hue = hue
65                         println("The hue level of the light is changed to $hue!")
66                         sendEvent([name: "hue", value: "$hue", deviceId: this.id, descriptionText: "",
67                                    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
68                 }
69         }
70
71         def setSaturation(int saturation) {
72                 if (saturation != this.saturation) {
73                         this.saturation = saturation
74                         println("The saturation level of the light is changed to $saturation!")
75                         sendEvent([name: "saturation", value: "$saturation", deviceId: this.id, descriptionText: "",
76                                    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
77                 }
78         }
79
80         def setLevel(int level) {
81                 if (level != this.level) {
82                         this.level = level
83                         println("The level of the light is changed to $level!")
84                         sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
85                                    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
86                 }
87         }
88
89         def setColorTemperature(int colorTemperature) {
90                 if (colorTemperature != this.colorTemperature) {
91                         this.colorTemperature = colorTemperature
92                         println("The color temperature level of the light is changed to $colorTemperature!")
93                         sendEvent([name: "colorTemperature", value: "$colorTemperature", deviceId: this.id, descriptionText: "",
94                                    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
95                 }
96         }
97
98         def on(String currentSwitch) {
99                 if (currentSwitch != this.currentSwitch) {
100                         this.currentSwitch = currentSwitch
101                         println("The light is changed to $currentSwitch!")
102                         sendEvent([name: "switch", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
103                                    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
104                         sendEvent([name: "switch.on", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
105                                    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
106                 }
107         }
108
109         def off(String currentSwitch) {
110                 if (currentSwitch != this.currentSwitch) {
111                         this.currentSwitch = currentSwitch
112                         println("The light is changed to $currentSwitch!")
113                         sendEvent([name: "switch", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
114                                    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
115                         sendEvent([name: "switch.off", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
116                                    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
117                 }
118         }
119
120         def currentValue(String deviceFeature) {
121                 if (deviceFeature == "color") {
122                         return color
123                 } else if (deviceFeature == "saturation") {
124                         return saturation
125                 } else if (deviceFeature == "hue") {
126                         return hue
127                 } else if (deviceFeature == "level") {
128                         return level
129                 } else if (deviceFeature == "colorTemperature") {
130                         return colorTemperature
131                 } else if (deviceFeature == "switch") {
132                         return currentSwitch
133                 }
134         }
135
136         def latestValue(String deviceFeature) {
137                 if (deviceFeature == "color") {
138                         return color
139                 } else if (deviceFeature == "saturation") {
140                         return saturation
141                 } else if (deviceFeature == "hue") {
142                         return hue
143                 } else if (deviceFeature == "level") {
144                         return level
145                 } else if (deviceFeature == "colorTemperature") {
146                         return colorTemperature
147                 } else if (deviceFeature == "switch") {
148                         return currentSwitch
149                 }
150         }
151 }