1 //Create a class for color temperature
2 package ColorTemperature
3 import Timer.SimulatedTimer
5 public class ColorTemperatures {
6 private int deviceNumbers
7 private List colorTemperatues
10 //For one device(We cannot have obj.id)-> We should have obj[0].id
11 private String id = "colorTemperatureID0"
12 private String label = "colorTemperature0"
13 private String displayName = "colorTemperature0"
14 private String currentSwitch = "on"
15 private int level = 50
16 private int currentLevel = 50
17 private int colorTemperature = 15000
20 ColorTemperatures(Closure sendEvent, int deviceNumbers, boolean init) {
21 this.sendEvent = sendEvent
22 this.deviceNumbers = deviceNumbers
23 this.colorTemperatues = []
27 this.currentLevel = 40
28 this.colorTemperature = 10000
31 this.currentLevel = 50
32 this.colorTemperature = 15000
35 colorTemperatues.add(new ColorTemperature(sendEvent, id, label, displayName, this.level, this.currentSwitch, this.colorTemperature))
38 //Methods for closures
39 def count(Closure Input) {
40 colorTemperatues.count(Input)
43 colorTemperatues.size()
45 def each(Closure Input) {
46 colorTemperatues.each(Input)
48 def find(Closure Input) {
49 colorTemperatues.find(Input)
51 def sort(Closure Input) {
52 colorTemperatues.sort(Input)
54 def collect(Closure Input) {
55 colorTemperatues.collect(Input)
59 def setValue(LinkedHashMap eventDataMap) {
60 if (eventDataMap["name"] == "switch") {
61 if (eventDataMap["value"] != colorTemperatues[0].currentSwitch) {
62 this.currentSwitch = eventDataMap["value"]
63 colorTemperatues[0].setValue(eventDataMap["value"], "switch")
64 sendEvent(eventDataMap)
66 } else if (eventDataMap["name"] == "colorTemperature") {
67 if (eventDataMap["value"].toInteger() != colorTemperatues[0].colorTemperature) {
68 this.colorTemperature = eventDataMap["value"].toInteger()
69 colorTemperatues[0].setValue(eventDataMap["value"], "colorTemperature")
70 sendEvent(eventDataMap)
72 } else if (eventDataMap["name"] == "level") {
73 if (eventDataMap["value"].toInteger() != colorTemperatues[0].level) {
74 this.currentLevel = eventDataMap["value"].toInteger()
75 this.level = eventDataMap["value"].toInteger()
76 colorTemperatues[0].setValue(eventDataMap["value"], "level")
77 sendEvent(eventDataMap)
84 def setLevel(long level) {
85 if (level != this.level) {
86 this.currentLevel = level
88 colorTemperatues[0].setLevel(level)
92 def setLevel(int level) {
93 if (level != this.level) {
94 this.currentLevel = level
96 colorTemperatues[0].setLevel(level)
100 def setColorTemperature(String colorTemperature) {
101 if (colorTemperature != this.colorTemperature) {
102 this.colorTemperature = colorTemperature
103 colorTemperatues[0].setColorTemperature(colorTemperature)
107 def setColorTemperature(int colorTemperature) {
108 if (colorTemperature != this.colorTemperature) {
109 this.colorTemperature = colorTemperature
110 colorTemperatues[0].setColorTemperature(colorTemperature)
114 def on(String currentSwitch) {
115 if (currentSwitch != this.currentSwitch) {
116 this.currentSwitch = currentSwitch
117 colorTemperatues[0].on(currentSwitch)
121 def off(String currentSwitch) {
122 if (currentSwitch != this.currentSwitch) {
123 this.currentSwitch = currentSwitch
124 colorTemperatues[0].off(currentSwitch)
128 def currentValue(String deviceFeature) {
129 colorTemperatues[0].currentValue(deviceFeature)
132 def latestValue(String deviceFeature) {
133 colorTemperatues[0].latestValue(deviceFeature)