X-Git-Url: http://plrg.eecs.uci.edu/git/?p=smartthings-infrastructure.git;a=blobdiff_plain;f=ColorControl%2FColorControl.groovy;fp=ColorControl%2FColorControl.groovy;h=4380f24408c0c5534d994ae06440b5625101a79c;hp=c278f4ae3a8fb6d73c50cee473c867b3df713058;hb=2d26e7af07daad1394408bdcf76150b5aacf3a8a;hpb=83071d3bcfc33f015ece13868342644498a9dda3 diff --git a/ColorControl/ColorControl.groovy b/ColorControl/ColorControl.groovy index c278f4a..4380f24 100644 --- a/ColorControl/ColorControl.groovy +++ b/ColorControl/ColorControl.groovy @@ -2,26 +2,18 @@ package ColorControl import SmartThing.SmartThing -//Importing mutable integer class -import MutableInteger.MutableInteger - public class ColorControl extends SmartThing { // id, label, and display name of the device - StringBuilder id = new StringBuilder() - StringBuilder label = new StringBuilder() - StringBuilder displayName = new StringBuilder() - // Features with numberical values - MutableInteger currentHue = new MutableInteger() - MutableInteger currentSaturation = new MutableInteger() - // Features with string values - StringBuilder currentColor = new StringBuilder() + String id + String label + String displayName // Maps from features to values - HashMap deviceValuesMap = new HashMap() - HashMap deviceIntValuesMap = new HashMap() + HashMap deviceValuesMap = new HashMap() + HashMap deviceIntValuesMap = new HashMap() - ColorControl(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentColor, MutableInteger currentHue, MutableInteger currentSaturation) { - deviceValuesMap = deviceValueSmartThing - deviceIntValuesMap = deviceIntValueSmartThing + ColorControl(Closure sendEvent, String id, String label, String displayName, String currentColor, Integer currentHue, Integer currentSaturation) { + deviceValueSmartThing = deviceValuesMap + deviceIntValueSmartThing = deviceIntValuesMap idSmartThing = id labelSmartThing = label displayNameSmartThing = displayName @@ -31,9 +23,6 @@ public class ColorControl extends SmartThing { this.id = id this.label = label this.displayName = displayName - this.currentHue = currentHue - this.currentSaturation = currentSaturation - this.currentColor = currentColor deviceValuesMap.put("color", currentColor) deviceIntValuesMap.put("hue", currentHue) @@ -74,11 +63,11 @@ public class ColorControl extends SmartThing { // Methods to set values def setColor(String newValue) { - action(currentColor, newValue, "color") + action(newValue, "color") } def setHue(int newValue) { - action(currentHue, newValue, "hue") + action(newValue, "hue") } def setHue(double newValue) { @@ -86,43 +75,10 @@ public class ColorControl extends SmartThing { } def setSaturation(int newValue) { - action(currentSaturation, newValue, "saturation") + action(newValue, "saturation") } def setSaturation(double newValue) { setSaturation((int) newValue) } - - def action(StringBuilder variable, String newValue, String feature) { - if (!variable.toString().equals(newValue)) { - String tmpID = id.toString() - variable.replace(0, variable.length(), newValue) - println("$feature of the light with id:$id is changed to $newValue!") - sendEvent([name: feature, value: newValue, deviceId: tmpID, descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) - } - } - - def action(MutableInteger variable, int newValue, String feature) { - if (!variable.getValue().equals(newValue)) { - String tmpID = id.toString() - variable.setValue(newValue) - println("$feature of the light with id:$id is changed to $newValue!") - sendEvent([name: feature, value: newValue, deviceId: tmpID, descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) - } - } - - // Methods to return values - def getCurrentHue() { - return currentHue.getValue() - } - - def getCurrentSaturation() { - return currentSaturation.getValue() - } - - def getCurrentColor() { - return currentColor.toString() - } }