X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=ColorControl%2FColorControl.groovy;h=f24d274ad61ed0bf98736a9e1d5679e3378ab099;hb=4e6463b38690279fa3ea38f4d8ef09827d8d6b09;hp=4d6eaf7ceb53b54aa58ef2627c49ba14b091300a;hpb=21d738a5813bcb99b370ad3559584cfd8d219f6b;p=smartthings-infrastructure.git diff --git a/ColorControl/ColorControl.groovy b/ColorControl/ColorControl.groovy index 4d6eaf7..f24d274 100644 --- a/ColorControl/ColorControl.groovy +++ b/ColorControl/ColorControl.groovy @@ -9,10 +9,14 @@ public class ColorControl { private String label private String displayName private String color + private String currentColor private String currentSwitch private int level + private int currentLevel private int hue + private int currentHue private int saturation + private int currentSaturation private int colorTemperature ColorControl(Closure sendEvent, String id, String label, String displayName, String color, int hue, int saturation, int level, String currentSwitch, int colorTemperature) { @@ -20,9 +24,13 @@ public class ColorControl { this.label = label this.displayName = displayName this.color = color + this.currentColor = color this.hue = hue + this.currentHue = hue this.saturation = saturation + this.currentSaturation = saturation this.level = level + this.currentLevel = level this.currentSwitch = currentSwitch this.colorTemperature = colorTemperature this.sendEvent = sendEvent @@ -32,14 +40,18 @@ public class ColorControl { def setValue(String value, String name) { if ((name == "color") && (value != this.color)) { this.color = value + this.currentColor = value println("the color of the light is changed to $value!") } else if ((name == "hue") && (value != this.hue)) { this.hue = value.toInteger() + this.currentHue = value.toInteger() println("The hue level of the light is changed to $value!") } else if ((name == "saturation") && (value != this.saturation)) { this.saturation = value.toInteger() + this.currentSaturation = value.toInteger() println("The saturation level of the light is changed to $value!") } else if ((name == "level") && (value != this.level)) { + this.currentLevel = value.toInteger() this.level = value.toInteger() println("The level of the light is changed to $value!") } else if ((name == "currentSwitch") && (value != this.currentSwitch)) { @@ -52,8 +64,47 @@ public class ColorControl { } //methods + def setColor(LinkedHashMap metaData) { + def hexColor = metaData.hex + def newColor + switch (hexColor) { + case "#0000FF": + newColor = "Blue" + break; + case "#00FF00": + newColor = "Green" + break; + case "#FFFF00": + newColor = "Yellow" + break; + case "#FF6000": + newColor = "Orange" + break; + case "#BF7FBF": + newColor = "Purple" + break; + case "#FF5F5F": + newColor = "Pink" + break; + case "#FF0000": + newColor = "Red" + break; + default: + newColor = "Blue" + break; + } + if (newColor != this.color) { + this.currentColor = newColor + this.color = newColor + println("The color of the light is changed to $newColor!") + sendEvent([name: "color", value: "$newColor", deviceId: this.id, descriptionText: "", + displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) + } + } + def setColor(String color) { if (color != this.color) { + this.currentColor = color this.color = color println("The color of the light is changed to $color!") sendEvent([name: "color", value: "$color", deviceId: this.id, descriptionText: "", @@ -64,6 +115,17 @@ public class ColorControl { def setHue(int hue) { if (hue != this.hue) { this.hue = hue + this.currentHue = hue + println("The hue level of the light is changed to $hue!") + sendEvent([name: "hue", value: "$hue", deviceId: this.id, descriptionText: "", + displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) + } + } + + def setHue(double hue) { + if (hue != this.hue) { + this.hue = hue + this.currentHue = hue println("The hue level of the light is changed to $hue!") sendEvent([name: "hue", value: "$hue", deviceId: this.id, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) @@ -72,6 +134,17 @@ public class ColorControl { def setSaturation(int saturation) { if (saturation != this.saturation) { + this.currentSaturation = saturation + this.saturation = saturation + println("The saturation level of the light is changed to $saturation!") + sendEvent([name: "saturation", value: "$saturation", deviceId: this.id, descriptionText: "", + displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) + } + } + + def setSaturation(double saturation) { + if (saturation != this.saturation) { + this.currentSaturation = saturation this.saturation = saturation println("The saturation level of the light is changed to $saturation!") sendEvent([name: "saturation", value: "$saturation", deviceId: this.id, descriptionText: "", @@ -79,8 +152,20 @@ public class ColorControl { } } + def setLevel(int level) { if (level != this.level) { + this.currentLevel = 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 setLevel(long level) { + if (level != this.level) { + this.currentLevel = level this.level = level println("The level of the light is changed to $level!") sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "", @@ -97,24 +182,20 @@ public class ColorControl { } } - def on(String currentSwitch) { - if (currentSwitch != this.currentSwitch) { + def on() { + if (this.currentSwitch != "on") { 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: "", + println("The light is changed to on!") + sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) } } - def off(String currentSwitch) { - if (currentSwitch != this.currentSwitch) { + def off() { + if (this.currentSwitch != "off") { 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: "", + println("The light is changed to off!") + sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) } }