//Create a class for color control
package ColorControl
-import Timer.SimulatedTimer
+import SmartThing.SmartThings
+//Importing mutable integer class
+import MutableInteger.MutableInteger
-public class ColorControls {
- private int deviceNumbers
- private List colorControls
- def sendEvent
-
- //For one device(We cannot have obj.id)-> We should have obj[0].id
- private String id = "colorControlID0"
- private String label = "colorControl0"
- private String displayName = "colorControl0"
- private String color = "red"
- private int hue = 50
- private int saturation = 50
+public class ColorControls extends SmartThings {
+ List colorControls = new ArrayList()
-
- ColorControls(Closure sendEvent, int deviceNumbers) {
- this.sendEvent = sendEvent
- this.deviceNumbers = deviceNumbers
- this.colorControls = []
-
- colorControls.add(new ColorControl(id, label, displayName, this.color, this.hue, this.saturation))
- }
+ ColorControls(Closure sendEvent, boolean init) {
+ // Only initialize one time since we only have one device for each capability
+ colorControls = smartThings
- //Methods for closures
- def count(Closure Input) {
- colorControls.count(Input)
- }
- def size() {
- colorControls.size()
- }
- def each(Closure Input) {
- colorControls.each(Input)
- }
- def find(Closure Input) {
- colorControls.find(Input)
- }
- def collect(Closure Input) {
- colorControls.collect(Input)
- }
+ // Initialization
+ StringBuilder id = new StringBuilder("colorControlID0")
+ StringBuilder label = new StringBuilder("colorControl")
+ StringBuilder displayName = new StringBuilder("colorControl0")
+ StringBuilder color = new StringBuilder()
+ MutableInteger hue = new MutableInteger()
+ MutableInteger saturation = new MutableInteger()
- //By model checker
- def setValue(LinkedHashMap eventDataMap) {
- if (eventDataMap["name"] == "color") {
- if (eventDataMap["value"] != colorControls[0].color) {
- colorControls[0].setValue(eventDataMap["value"], "color")
- this.color = colorControls[0].color
- sendEvent(eventDataMap)
- }
- } else if (eventDataMap["name"] == "hue") {
- if (eventDataMap["value"] != colorControls[0].hue) {
- colorControls[0].setValue(eventDataMap["value"], "hue")
- this.hue = colorControls[0].hue
- sendEvent(eventDataMap)
- }
- } else {
- if (eventDataMap["value"] != colorControls[0].saturation) {
- colorControls[0].setValue(eventDataMap["value"], "saturation")
- this.saturation = colorControls[0].saturation
- sendEvent(eventDataMap)
- }
+ if (init) {
+ color.append("Red")
+ hue.setValue(30)
+ saturation.setValue(40)
+ } else {
+ color.append("Blue")
+ hue.setValue(50)
+ saturation.setValue(50)
}
+
+ colorControls.add(new ColorControl(sendEvent, id, label, displayName, color, hue,
+ saturation))
}
+ // Methods to set values
+ def setColor(LinkedHashMap metaData) {
+ colorControls[0].setColor(metaData)
+ }
- //methods
def setColor(String color) {
colorControls[0].setColor(color)
- this.color = color
}
def setHue(int hue) {
colorControls[0].setHue(hue)
- this.hue = hue
+ }
+
+ def setHue(double hue) {
+ colorControls[0].setHue((int) hue)
}
def setSaturation(int saturation) {
- colorControls[0].setSaturation(saturation)
- this.saturation = saturation
+ colorControls[0].setSaturation(saturation)
+ }
+
+ def setSaturation(double saturation) {
+ colorControls[0].setSaturation((int) saturation)
+ }
+
+ def on() {
+ colorControls[0].on()
+ }
+
+ def off() {
+ colorControls[0].off()
}
- def currentValue(String deviceFeature) {
- colorControls[0].currentValue(deviceFeature)
+ // Methods to return values
+ def getCurrentHue() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(colorControls[0].getCurrentHue())
+ return tmpValues
}
- def getAt(int ix) {
- colorControls[ix]
+ def getCurrentSaturation() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(colorControls[0].getCurrentSaturation())
+ return tmpValues
+ }
+
+ def getCurrentColor() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(colorControls[0].getCurrentColor())
+ return tmpValues
}
}