X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=ColorControl%2FColorControl.groovy;h=e0a905f4fe554795279983c62d67d6d0876852ec;hb=b30c5b2dd2567206e9b19313610fbd104ebdb373;hp=cd33e8e6ebc7756d27447d5af1a16809c09ce07d;hpb=6b033926fc678d37f4509f6f86a6264803ef904f;p=smartthings-infrastructure.git diff --git a/ColorControl/ColorControl.groovy b/ColorControl/ColorControl.groovy index cd33e8e..e0a905f 100644 --- a/ColorControl/ColorControl.groovy +++ b/ColorControl/ColorControl.groovy @@ -64,6 +64,44 @@ 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 @@ -83,6 +121,16 @@ public class ColorControl { 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"}']) + } + } def setSaturation(int saturation) { if (saturation != this.saturation) { @@ -104,6 +152,16 @@ public class ColorControl { } } + 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: "", + displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) + } + } + def setColorTemperature(int colorTemperature) { if (colorTemperature != this.colorTemperature) { this.colorTemperature = colorTemperature @@ -113,24 +171,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"}']) } }