1 //Create a class for color temperature
2 package ColorTemperature
3 import Timer.SimulatedTimer
6 import gov.nasa.jpf.vm.Verify
8 public class ColorTemperatures {
9 private int deviceNumbers
10 private List colorTemperatues
13 //For one device(We cannot have obj.id)-> We should have obj[0].id
14 private String id = "colorTemperatureID0"
15 private String label = "colorTemperature0"
16 private String displayName = "colorTemperature0"
17 private String currentSwitch = "on"
18 private int level = 50
19 private int currentLevel = 50
20 private int colorTemperature = 15000
23 ColorTemperatures(Closure sendEvent, int deviceNumbers) {
24 this.sendEvent = sendEvent
25 this.deviceNumbers = deviceNumbers
26 this.colorTemperatues = []
28 /*def initLevel = Verify.getIntFromList(50, 70)
29 this.level = initLevel
30 def initTemp = Verify.getIntFromList(10000, 15000)
31 this.colorTemperature = initTemp
32 def init = Verify.getBoolean()
34 this.currentSwitch = "off"
36 this.currentSwitch = "on"
39 colorTemperatues.add(new ColorTemperature(sendEvent, id, label, displayName, this.level, this.currentSwitch, this.colorTemperature))
42 //Methods for closures
43 def count(Closure Input) {
44 colorTemperatues.count(Input)
47 colorTemperatues.size()
49 def each(Closure Input) {
50 colorTemperatues.each(Input)
52 def find(Closure Input) {
53 colorTemperatues.find(Input)
55 def sort(Closure Input) {
56 colorTemperatues.sort(Input)
58 def collect(Closure Input) {
59 colorTemperatues.collect(Input)
63 def setValue(LinkedHashMap eventDataMap) {
64 if (eventDataMap["name"] == "switch") {
65 if (eventDataMap["value"] != colorTemperatues[0].currentSwitch) {
66 this.currentSwitch = eventDataMap["value"]
67 colorTemperatues[0].setValue(eventDataMap["value"], "switch")
68 sendEvent(eventDataMap)
70 } else if (eventDataMap["name"] == "colorTemperature") {
71 if (eventDataMap["value"].toInteger() != colorTemperatues[0].colorTemperature) {
72 this.colorTemperature = eventDataMap["value"].toInteger()
73 colorTemperatues[0].setValue(eventDataMap["value"], "colorTemperature")
74 sendEvent(eventDataMap)
76 } else if (eventDataMap["name"] == "level") {
77 if (eventDataMap["value"].toInteger() != colorTemperatues[0].level) {
78 this.currentLevel = eventDataMap["value"].toInteger()
79 this.level = eventDataMap["value"].toInteger()
80 colorTemperatues[0].setValue(eventDataMap["value"], "level")
81 sendEvent(eventDataMap)
88 def setLevel(long level) {
89 if (level != this.level) {
90 this.currentLevel = level
92 colorTemperatues[0].setLevel(level)
96 def setLevel(int level) {
97 if (level != this.level) {
98 this.currentLevel = level
100 colorTemperatues[0].setLevel(level)
104 def setColorTemperature(String colorTemperature) {
105 if (colorTemperature != this.colorTemperature) {
106 this.colorTemperature = colorTemperature
107 colorTemperatues[0].setColorTemperature(colorTemperature)
111 def setColorTemperature(int colorTemperature) {
112 if (colorTemperature != this.colorTemperature) {
113 this.colorTemperature = colorTemperature
114 colorTemperatues[0].setColorTemperature(colorTemperature)
118 def on(String currentSwitch) {
119 if (currentSwitch != this.currentSwitch) {
120 this.currentSwitch = currentSwitch
121 colorTemperatues[0].on(currentSwitch)
125 def off(String currentSwitch) {
126 if (currentSwitch != this.currentSwitch) {
127 this.currentSwitch = currentSwitch
128 colorTemperatues[0].off(currentSwitch)
132 def currentValue(String deviceFeature) {
133 colorTemperatues[0].currentValue(deviceFeature)
136 def latestValue(String deviceFeature) {
137 colorTemperatues[0].latestValue(deviceFeature)