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 = "off"
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 init = Verify.getInt(0,2)
45 colorControls.add(new ColorControl(sendEvent, id, label, displayName, this.color, this.hue, this.saturation, this.level, this.currentSwitch, this.colorTemperature))
48 //Methods for closures
49 def count(Closure Input) {
50 colorControls.count(Input)
55 def each(Closure Input) {
56 colorControls.each(Input)
58 def find(Closure Input) {
59 colorControls.find(Input)
61 def sort(Closure Input) {
62 colorControls.sort(Input)
64 def collect(Closure Input) {
65 colorControls.collect(Input)
69 def setValue(LinkedHashMap eventDataMap) {
70 if (eventDataMap["name"] == "color") {
71 if (eventDataMap["value"] != colorControls[0].color) {
72 this.currentColor = eventDataMap["value"]
73 this.color = eventDataMap["value"]
74 colorControls[0].setValue(eventDataMap["value"], "color")
75 sendEvent(eventDataMap)
77 } else if (eventDataMap["name"] == "hue") {
78 if (eventDataMap["value"].toInteger() != colorControls[0].hue) {
79 this.hue = eventDataMap["value"].toInteger()
80 this.currentHue = eventDataMap["value"].toInteger()
81 colorControls[0].setValue(eventDataMap["value"], "hue")
82 sendEvent(eventDataMap)
84 } else if (eventDataMap["name"] == "saturation") {
85 if (eventDataMap["value"].toInteger() != colorControls[0].saturation) {
86 this.saturation = eventDataMap["value"].toInteger()
87 this.currentSaturation = eventDataMap["value"].toInteger()
88 colorControls[0].setValue(eventDataMap["value"], "saturation")
89 sendEvent(eventDataMap)
91 } else if (eventDataMap["name"] == "switch") {
92 if (eventDataMap["value"] != colorControls[0].currentSwitch) {
93 this.currentSwitch = eventDataMap["value"]
94 colorControls[0].setValue(eventDataMap["value"], "switch")
95 sendEvent(eventDataMap)
97 } else if (eventDataMap["name"] == "colorTemperature") {
98 if (eventDataMap["value"].toInteger() != colorControls[0].colorTemperature) {
99 this.colorTemperature = eventDataMap["value"].toInteger()
100 colorControls[0].setValue(eventDataMap["value"], "colorTemperature")
101 sendEvent(eventDataMap)
103 } else if (eventDataMap["name"] == "level") {
104 if (eventDataMap["value"].toInteger() != colorControls[0].level) {
105 this.currentLevel = eventDataMap["value"].toInteger()
106 this.level = eventDataMap["value"].toInteger()
107 colorControls[0].setValue(eventDataMap["value"], "level")
108 sendEvent(eventDataMap)
115 def setColor(String color) {
116 if (color != this.color) {
117 this.currentColor = color
119 colorControls[0].setColor(color)
123 def setHue(int hue) {
124 if (hue != this.hue) {
126 this.currentHue = hue
127 colorControls[0].setHue(hue)
131 def setSaturation(int saturation) {
132 if (saturation != this.saturation) {
133 this.currentSaturation = saturation
134 this.saturation = saturation
135 colorControls[0].setSaturation(saturation)
139 def setLevel(int level) {
140 if (level != this.level) {
141 this.currentLevel = level
143 colorControls[0].setLevel(level)
147 def setColorTemperature(String colorTemperature) {
148 if (colorTemperature != this.colorTemperature) {
149 this.colorTemperature = colorTemperature
150 colorControls[0].setColorTemperature(colorTemperature)
154 def on(String currentSwitch) {
155 if (currentSwitch != this.currentSwitch) {
156 this.currentSwitch = currentSwitch
157 colorControls[0].on(currentSwitch)
161 def off(String currentSwitch) {
162 if (currentSwitch != this.currentSwitch) {
163 this.currentSwitch = currentSwitch
164 colorControls[0].off(currentSwitch)
168 def currentValue(String deviceFeature) {
169 colorControls[0].currentValue(deviceFeature)
172 def latestValue(String deviceFeature) {
173 colorControls[0].latestValue(deviceFeature)