1 //Create a class for color control
3 import Timer.SimulatedTimer
6 public class ColorControls {
7 private int deviceNumbers
8 private List colorControls
11 //For one device(We cannot have obj.id)-> We should have obj[0].id
12 private String id = "colorControlID0"
13 private String label = "colorControl0"
14 private String displayName = "colorControl0"
15 private String color = "red"
17 private int saturation = 50
20 ColorControls(Closure sendEvent, int deviceNumbers) {
21 this.sendEvent = sendEvent
22 this.deviceNumbers = deviceNumbers
23 this.colorControls = []
25 colorControls.add(new ColorControl(id, label, displayName, this.color, this.hue, this.saturation))
28 //Methods for closures
29 def count(Closure Input) {
30 colorControls.count(Input)
35 def each(Closure Input) {
36 colorControls.each(Input)
38 def find(Closure Input) {
39 colorControls.find(Input)
41 def collect(Closure Input) {
42 colorControls.collect(Input)
46 def setValue(LinkedHashMap eventDataMap) {
47 if (eventDataMap["name"] == "color") {
48 if (eventDataMap["value"] != colorControls[0].color) {
49 colorControls[0].setValue(eventDataMap["value"], "color")
50 this.color = colorControls[0].color
51 sendEvent(eventDataMap)
53 } else if (eventDataMap["name"] == "hue") {
54 if (eventDataMap["value"] != colorControls[0].hue) {
55 colorControls[0].setValue(eventDataMap["value"], "hue")
56 this.hue = colorControls[0].hue
57 sendEvent(eventDataMap)
60 if (eventDataMap["value"] != colorControls[0].saturation) {
61 colorControls[0].setValue(eventDataMap["value"], "saturation")
62 this.saturation = colorControls[0].saturation
63 sendEvent(eventDataMap)
70 def setColor(String color) {
71 colorControls[0].setColor(color)
76 colorControls[0].setHue(hue)
80 def setSaturation(int saturation) {
81 colorControls[0].setSaturation(saturation)
82 this.saturation = saturation
85 def currentValue(String deviceFeature) {
86 colorControls[0].currentValue(deviceFeature)