X-Git-Url: http://plrg.eecs.uci.edu/git/?p=smartthings-infrastructure.git;a=blobdiff_plain;f=ColorControl%2FColorControls.groovy;h=0c0832b3921e650d870b2db8814bd212f4106a9b;hp=74964fe0cf131e6eff15e310f998ed85a6583a9e;hb=b7cf952d275d7cb67250c52404cf855ef57c1119;hpb=d3802bd96ca8963ae52b9740443f9be6896f0e18 diff --git a/ColorControl/ColorControls.groovy b/ColorControl/ColorControls.groovy index 74964fe..0c0832b 100644 --- a/ColorControl/ColorControls.groovy +++ b/ColorControl/ColorControls.groovy @@ -15,10 +15,14 @@ public class ColorControls { private String label = "colorControl0" private String displayName = "colorControl0" private String color = "red" + private String currentColor = "red" private String currentSwitch = "off" private int level = 50 + private int currentLevel = 50 private int hue = 50 + private int currentHue = 50 private int saturation = 50 + private int currentSaturation = 50 private int colorTemperature = 15000 @@ -27,20 +31,18 @@ public class ColorControls { this.deviceNumbers = deviceNumbers this.colorControls = [] - def initHue = Verify.getIntFromList(30, 50, 70) + def initHue = Verify.getIntFromList(30, 50) this.hue = initHue - def initSat = Verify.getIntFromList(40, 50, 60) + def initSat = Verify.getIntFromList(40, 50) this.saturation = initSat def init = Verify.getInt(0,2) if (init == 0) { this.color = "red" - } else if (init == 1) { - this.color = "green" } else { this.color = "blue" } - colorControls.add(new ColorControl(id, label, displayName, this.color, this.hue, this.saturation, this.level, this.currentSwitch, this.colorTemperature)) + colorControls.add(new ColorControl(sendEvent, id, label, displayName, this.color, this.hue, this.saturation, this.level, this.currentSwitch, this.colorTemperature)) } //Methods for closures @@ -67,6 +69,7 @@ public class ColorControls { def setValue(LinkedHashMap eventDataMap) { if (eventDataMap["name"] == "color") { if (eventDataMap["value"] != colorControls[0].color) { + this.currentColor = eventDataMap["value"] this.color = eventDataMap["value"] colorControls[0].setValue(eventDataMap["value"], "color") sendEvent(eventDataMap) @@ -74,12 +77,14 @@ public class ColorControls { } else if (eventDataMap["name"] == "hue") { if (eventDataMap["value"].toInteger() != colorControls[0].hue) { this.hue = eventDataMap["value"].toInteger() + this.currentHue = eventDataMap["value"].toInteger() colorControls[0].setValue(eventDataMap["value"], "hue") sendEvent(eventDataMap) } } else if (eventDataMap["name"] == "saturation") { if (eventDataMap["value"].toInteger() != colorControls[0].saturation) { this.saturation = eventDataMap["value"].toInteger() + this.currentSaturation = eventDataMap["value"].toInteger() colorControls[0].setValue(eventDataMap["value"], "saturation") sendEvent(eventDataMap) } @@ -97,6 +102,7 @@ public class ColorControls { } } else if (eventDataMap["name"] == "level") { if (eventDataMap["value"].toInteger() != colorControls[0].level) { + this.currentLevel = eventDataMap["value"].toInteger() this.level = eventDataMap["value"].toInteger() colorControls[0].setValue(eventDataMap["value"], "level") sendEvent(eventDataMap) @@ -108,6 +114,7 @@ public class ColorControls { //methods def setColor(String color) { if (color != this.color) { + this.currentColor = color this.color = color colorControls[0].setColor(color) } @@ -115,13 +122,15 @@ public class ColorControls { def setHue(int hue) { if (hue != this.hue) { - this.hue = hue + this.hue = hue + this.currentHue = hue colorControls[0].setHue(hue) } } def setSaturation(int saturation) { if (saturation != this.saturation) { + this.currentSaturation = saturation this.saturation = saturation colorControls[0].setSaturation(saturation) } @@ -129,6 +138,7 @@ public class ColorControls { def setLevel(int level) { if (level != this.level) { + this.currentLevel = level this.level = level colorControls[0].setLevel(level) }