Changes in classes: new concept for latest value + all types of events generated...
[smartthings-infrastructure.git] / ColorControl / ColorControl.groovy
index ac80290ee4c192311e17ee3fd1756b0ea3227eb8..53658dce6e3ddb542ee1f616f6a7fa4174fd195d 100644 (file)
@@ -8,16 +8,22 @@ public class ColorControl {
        private String label
        private String displayName
        private String color
+       private String currentSwitch
+       private int level
        private int hue
        private int saturation
+       private int colorTemperature
        
-       ColorControl(String id, String label, String displayName, String color, int hue, int saturation) {
+       ColorControl(String id, String label, String displayName, String color, int hue, int saturation, int level, String currentSwitch, int colorTemperature) {
                this.id = id
                this.label = label
                this.displayName = displayName
                this.color = color
                this.hue = hue
                this.saturation = saturation
+               this.level = level
+               this.currentSwitch = currentSwitch
+               this.colorTemperature = colorTemperature
        }
        
        //By model checker
@@ -28,9 +34,18 @@ public class ColorControl {
                } else if ((name == "hue") && (value != this.hue)) {
                        this.hue = value.toInteger()
                        println("The hue level of the light is changed to $value!")
-               } else if (value != this.saturation) {
+               } else if ((name == "saturation") && (value != this.saturation)) {
                        this.saturation = value.toInteger()
                        println("The saturation level of the light is changed to $value!")
+               } else if ((name == "level") && (value != this.level)) {
+                       this.level = value.toInteger()
+                       println("The level of the light is changed to $value!")
+               } else if ((name == "currentSwitch") && (value != this.currentSwitch)) {
+                       this.currentSwitch = value
+                       println("The light is changed to $value!")
+               } else if ((name == "colorTemperature") && (value != this.colorTemperature)) {
+                       this.colorTemperature = value.toInteger()
+                       println("The color temperature level of the light is changed to $value!")
                }
        }
 
@@ -62,6 +77,46 @@ public class ColorControl {
                }
        }
 
+       def setLevel(int level) {
+               if (level != this.level) {
+                       this.level = level
+                       println("The level of the light is changed to $level!")
+                       sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
+       }
+
+       def setColorTemperature(int colorTemperature) {
+               if (colorTemperature != this.colorTemperature) {
+                       this.colorTemperature = colorTemperature
+                       println("The color temperature level of the light is changed to $colorTemperature!")
+                       sendEvent([name: "colorTemperature", value: "$colorTemperature", deviceId: this.id, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
+       }
+
+       def on(String currentSwitch) {
+               if (currentSwitch != this.currentSwitch) {
+                       this.currentSwitch = currentSwitch
+                       println("The light is changed to $currentSwitch!")
+                       sendEvent([name: "switch", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+                       sendEvent([name: "switch.on", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
+       }
+
+       def off(String currentSwitch) {
+               if (currentSwitch != this.currentSwitch) {
+                       this.currentSwitch = currentSwitch
+                       println("The light is changed to $currentSwitch!")
+                       sendEvent([name: "switch", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+                       sendEvent([name: "switch.off", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
+       }
+
        def currentValue(String deviceFeature) {
                if (deviceFeature == "color") {
                        return color
@@ -69,6 +124,28 @@ public class ColorControl {
                        return saturation
                } else if (deviceFeature == "hue") {
                        return hue
+               } else if (deviceFeature == "level") {
+                       return level
+               } else if (deviceFeature == "colorTemperature") {
+                       return colorTemperature
+               } else if (deviceFeature == "switch") {
+                       return currentSwitch
+               }
+       }
+
+       def latestValue(String deviceFeature) {
+               if (deviceFeature == "color") {
+                       return color
+               } else if (deviceFeature == "saturation") {
+                       return saturation
+               } else if (deviceFeature == "hue") {
+                       return hue
+               } else if (deviceFeature == "level") {
+                       return level
+               } else if (deviceFeature == "colorTemperature") {
+                       return colorTemperature
+               } else if (deviceFeature == "switch") {
+                       return currentSwitch
                }
        }
 }