1 //Create a class for color control
3 import Timer.SimulatedTimer
6 import gov.nasa.jpf.vm.Verify
8 public class ColorControls {
9 private int deviceNumbers
10 private List colorControls
13 //For one device(We cannot have obj.id)-> We should have obj[0].id
14 private String id = "colorControlID0"
15 private String label = "colorControl0"
16 private String displayName = "colorControl0"
17 private String color = "red"
18 private String currentColor = "red"
19 private String currentSwitch = "on"
20 private int level = 50
21 private int currentLevel = 50
23 private int currentHue = 50
24 private int saturation = 50
25 private int currentSaturation = 50
26 private int colorTemperature = 15000
29 ColorControls(Closure sendEvent, int deviceNumbers) {
30 this.sendEvent = sendEvent
31 this.deviceNumbers = deviceNumbers
32 this.colorControls = []
34 /*def initHue = Verify.getIntFromList(30, 50)
36 def initSat = Verify.getIntFromList(40, 50)
37 this.saturation = initSat
38 def initColor = Verify.getBoolean()
44 def init = Verify.getBoolean()
46 this.currentSwitch = "off"
48 this.currentSwitch = "on"
51 colorControls.add(new ColorControl(sendEvent, id, label, displayName, this.color, this.hue, this.saturation, this.level, this.currentSwitch, this.colorTemperature))
54 //Methods for closures
55 def count(Closure Input) {
56 colorControls.count(Input)
61 def each(Closure Input) {
62 colorControls.each(Input)
64 def find(Closure Input) {
65 colorControls.find(Input)
67 def sort(Closure Input) {
68 colorControls.sort(Input)
70 def collect(Closure Input) {
71 colorControls.collect(Input)
75 def setValue(LinkedHashMap eventDataMap) {
76 if (eventDataMap["name"] == "color") {
77 if (eventDataMap["value"] != colorControls[0].color) {
78 this.currentColor = eventDataMap["value"]
79 this.color = eventDataMap["value"]
80 colorControls[0].setValue(eventDataMap["value"], "color")
81 sendEvent(eventDataMap)
83 } else if (eventDataMap["name"] == "hue") {
84 if (eventDataMap["value"].toInteger() != colorControls[0].hue) {
85 this.hue = eventDataMap["value"].toInteger()
86 this.currentHue = eventDataMap["value"].toInteger()
87 colorControls[0].setValue(eventDataMap["value"], "hue")
88 sendEvent(eventDataMap)
90 } else if (eventDataMap["name"] == "saturation") {
91 if (eventDataMap["value"].toInteger() != colorControls[0].saturation) {
92 this.saturation = eventDataMap["value"].toInteger()
93 this.currentSaturation = eventDataMap["value"].toInteger()
94 colorControls[0].setValue(eventDataMap["value"], "saturation")
95 sendEvent(eventDataMap)
97 } else if (eventDataMap["name"] == "switch") {
98 if (eventDataMap["value"] != colorControls[0].currentSwitch) {
99 this.currentSwitch = eventDataMap["value"]
100 colorControls[0].setValue(eventDataMap["value"], "switch")
101 sendEvent(eventDataMap)
103 } else if (eventDataMap["name"] == "colorTemperature") {
104 if (eventDataMap["value"].toInteger() != colorControls[0].colorTemperature) {
105 this.colorTemperature = eventDataMap["value"].toInteger()
106 colorControls[0].setValue(eventDataMap["value"], "colorTemperature")
107 sendEvent(eventDataMap)
109 } else if (eventDataMap["name"] == "level") {
110 if (eventDataMap["value"].toInteger() != colorControls[0].level) {
111 this.currentLevel = eventDataMap["value"].toInteger()
112 this.level = eventDataMap["value"].toInteger()
113 colorControls[0].setValue(eventDataMap["value"], "level")
114 sendEvent(eventDataMap)
121 def setColor(LinkedHashMap metaData) {
122 def hexColor = metaData.hex
149 if (color != this.color) {
150 this.currentColor = color
152 colorControls[0].setColor(color)
156 def setColor(String color) {
157 if (color != this.color) {
158 this.currentColor = color
160 colorControls[0].setColor(color)
164 def setHue(int hue) {
165 if (hue != this.hue) {
167 this.currentHue = hue
168 colorControls[0].setHue(hue)
172 def setSaturation(int saturation) {
173 if (saturation != this.saturation) {
174 this.currentSaturation = saturation
175 this.saturation = saturation
176 colorControls[0].setSaturation(saturation)
180 def setLevel(int level) {
181 if (level != this.level) {
182 this.currentLevel = level
184 colorControls[0].setLevel(level)
188 def setColorTemperature(int colorTemperature) {
189 if (colorTemperature != this.colorTemperature) {
190 this.colorTemperature = colorTemperature
191 colorControls[0].setColorTemperature(colorTemperature)
196 if (this.currentSwitch != "on") {
197 this.currentSwitch = "on"
198 colorControls[0].on()
203 if (this.currentSwitch != "off") {
204 this.currentSwitch = "off"
205 colorControls[0].off()
209 def currentValue(String deviceFeature) {
210 colorControls[0].currentValue(deviceFeature)
213 def latestValue(String deviceFeature) {
214 colorControls[0].latestValue(deviceFeature)