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, 70)
36 def initSat = Verify.getIntFromList(40, 50, 60)
37 this.saturation = initSat
38 def init = Verify.getInt(0,2)
41 } else if (init == 1) {
47 colorControls.add(new ColorControl(sendEvent, id, label, displayName, this.color, this.hue, this.saturation, this.level, this.currentSwitch, this.colorTemperature))
50 //Methods for closures
51 def count(Closure Input) {
52 colorControls.count(Input)
57 def each(Closure Input) {
58 colorControls.each(Input)
60 def find(Closure Input) {
61 colorControls.find(Input)
63 def sort(Closure Input) {
64 colorControls.sort(Input)
66 def collect(Closure Input) {
67 colorControls.collect(Input)
71 def setValue(LinkedHashMap eventDataMap) {
72 if (eventDataMap["name"] == "color") {
73 if (eventDataMap["value"] != colorControls[0].color) {
74 this.currentColor = eventDataMap["value"]
75 this.color = eventDataMap["value"]
76 colorControls[0].setValue(eventDataMap["value"], "color")
77 sendEvent(eventDataMap)
79 } else if (eventDataMap["name"] == "hue") {
80 if (eventDataMap["value"].toInteger() != colorControls[0].hue) {
81 this.hue = eventDataMap["value"].toInteger()
82 this.currentHue = eventDataMap["value"].toInteger()
83 colorControls[0].setValue(eventDataMap["value"], "hue")
84 sendEvent(eventDataMap)
86 } else if (eventDataMap["name"] == "saturation") {
87 if (eventDataMap["value"].toInteger() != colorControls[0].saturation) {
88 this.saturation = eventDataMap["value"].toInteger()
89 this.currentSaturation = eventDataMap["value"].toInteger()
90 colorControls[0].setValue(eventDataMap["value"], "saturation")
91 sendEvent(eventDataMap)
93 } else if (eventDataMap["name"] == "switch") {
94 if (eventDataMap["value"] != colorControls[0].currentSwitch) {
95 this.currentSwitch = eventDataMap["value"]
96 colorControls[0].setValue(eventDataMap["value"], "switch")
97 sendEvent(eventDataMap)
99 } else if (eventDataMap["name"] == "colorTemperature") {
100 if (eventDataMap["value"].toInteger() != colorControls[0].colorTemperature) {
101 this.colorTemperature = eventDataMap["value"].toInteger()
102 colorControls[0].setValue(eventDataMap["value"], "colorTemperature")
103 sendEvent(eventDataMap)
105 } else if (eventDataMap["name"] == "level") {
106 if (eventDataMap["value"].toInteger() != colorControls[0].level) {
107 this.currentLevel = eventDataMap["value"].toInteger()
108 this.level = eventDataMap["value"].toInteger()
109 colorControls[0].setValue(eventDataMap["value"], "level")
110 sendEvent(eventDataMap)
117 def setColor(String color) {
118 if (color != this.color) {
119 this.currentColor = color
121 colorControls[0].setColor(color)
125 def setHue(int hue) {
126 if (hue != this.hue) {
128 this.currentHue = hue
129 colorControls[0].setHue(hue)
133 def setSaturation(int saturation) {
134 if (saturation != this.saturation) {
135 this.currentSaturation = saturation
136 this.saturation = saturation
137 colorControls[0].setSaturation(saturation)
141 def setLevel(int level) {
142 if (level != this.level) {
143 this.currentLevel = level
145 colorControls[0].setLevel(level)
149 def setColorTemperature(String colorTemperature) {
150 if (colorTemperature != this.colorTemperature) {
151 this.colorTemperature = colorTemperature
152 colorControls[0].setColorTemperature(colorTemperature)
156 def on(String currentSwitch) {
157 if (currentSwitch != this.currentSwitch) {
158 this.currentSwitch = currentSwitch
159 colorControls[0].on(currentSwitch)
163 def off(String currentSwitch) {
164 if (currentSwitch != this.currentSwitch) {
165 this.currentSwitch = currentSwitch
166 colorControls[0].off(currentSwitch)
170 def currentValue(String deviceFeature) {
171 colorControls[0].currentValue(deviceFeature)
174 def latestValue(String deviceFeature) {
175 colorControls[0].latestValue(deviceFeature)