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 currentSwitch = "off"
19 private int level = 50
21 private int saturation = 50
22 private int colorTemperature = 15000
25 ColorControls(Closure sendEvent, int deviceNumbers) {
26 this.sendEvent = sendEvent
27 this.deviceNumbers = deviceNumbers
28 this.colorControls = []
30 /*def initHue = Verify.getIntFromList(30, 50, 70)
32 def initSat = Verify.getIntFromList(40, 50, 60)
33 this.saturation = initSat
34 def init = Verify.getInt(0,2)
37 } else if (init == 1) {
43 colorControls.add(new ColorControl(sendEvent, id, label, displayName, this.color, this.hue, this.saturation, this.level, this.currentSwitch, this.colorTemperature))
46 //Methods for closures
47 def count(Closure Input) {
48 colorControls.count(Input)
53 def each(Closure Input) {
54 colorControls.each(Input)
56 def find(Closure Input) {
57 colorControls.find(Input)
59 def sort(Closure Input) {
60 colorControls.sort(Input)
62 def collect(Closure Input) {
63 colorControls.collect(Input)
67 def setValue(LinkedHashMap eventDataMap) {
68 if (eventDataMap["name"] == "color") {
69 if (eventDataMap["value"] != colorControls[0].color) {
70 this.color = eventDataMap["value"]
71 colorControls[0].setValue(eventDataMap["value"], "color")
72 sendEvent(eventDataMap)
74 } else if (eventDataMap["name"] == "hue") {
75 if (eventDataMap["value"].toInteger() != colorControls[0].hue) {
76 this.hue = eventDataMap["value"].toInteger()
77 colorControls[0].setValue(eventDataMap["value"], "hue")
78 sendEvent(eventDataMap)
80 } else if (eventDataMap["name"] == "saturation") {
81 if (eventDataMap["value"].toInteger() != colorControls[0].saturation) {
82 this.saturation = eventDataMap["value"].toInteger()
83 colorControls[0].setValue(eventDataMap["value"], "saturation")
84 sendEvent(eventDataMap)
86 } else if (eventDataMap["name"] == "switch") {
87 if (eventDataMap["value"] != colorControls[0].currentSwitch) {
88 this.currentSwitch = eventDataMap["value"]
89 colorControls[0].setValue(eventDataMap["value"], "switch")
90 sendEvent(eventDataMap)
92 } else if (eventDataMap["name"] == "colorTemperature") {
93 if (eventDataMap["value"].toInteger() != colorControls[0].colorTemperature) {
94 this.colorTemperature = eventDataMap["value"].toInteger()
95 colorControls[0].setValue(eventDataMap["value"], "colorTemperature")
96 sendEvent(eventDataMap)
98 } else if (eventDataMap["name"] == "level") {
99 if (eventDataMap["value"].toInteger() != colorControls[0].level) {
100 this.level = eventDataMap["value"].toInteger()
101 colorControls[0].setValue(eventDataMap["value"], "level")
102 sendEvent(eventDataMap)
109 def setColor(String color) {
110 if (color != this.color) {
112 colorControls[0].setColor(color)
116 def setHue(int hue) {
117 if (hue != this.hue) {
119 colorControls[0].setHue(hue)
123 def setSaturation(int saturation) {
124 if (saturation != this.saturation) {
125 this.saturation = saturation
126 colorControls[0].setSaturation(saturation)
130 def setLevel(int level) {
131 if (level != this.level) {
133 colorControls[0].setLevel(level)
137 def setColorTemperature(String colorTemperature) {
138 if (colorTemperature != this.colorTemperature) {
139 this.colorTemperature = colorTemperature
140 colorControls[0].setColorTemperature(colorTemperature)
144 def on(String currentSwitch) {
145 if (currentSwitch != this.currentSwitch) {
146 this.currentSwitch = currentSwitch
147 colorControls[0].on(currentSwitch)
151 def off(String currentSwitch) {
152 if (currentSwitch != this.currentSwitch) {
153 this.currentSwitch = currentSwitch
154 colorControls[0].off(currentSwitch)
158 def currentValue(String deviceFeature) {
159 colorControls[0].currentValue(deviceFeature)
162 def latestValue(String deviceFeature) {
163 colorControls[0].latestValue(deviceFeature)