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 = "off"
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 colorTemperatues.add(new ColorTemperature(sendEvent, id, label, displayName, this.level, this.currentSwitch, this.colorTemperature))
31 //Methods for closures
32 def count(Closure Input) {
33 colorTemperatues.count(Input)
36 colorTemperatues.size()
38 def each(Closure Input) {
39 colorTemperatues.each(Input)
41 def find(Closure Input) {
42 colorTemperatues.find(Input)
44 def sort(Closure Input) {
45 colorTemperatues.sort(Input)
47 def collect(Closure Input) {
48 colorTemperatues.collect(Input)
52 def setValue(LinkedHashMap eventDataMap) {
53 if (eventDataMap["name"] == "switch") {
54 if (eventDataMap["value"] != colorTemperatues[0].currentSwitch) {
55 this.currentSwitch = eventDataMap["value"]
56 colorTemperatues[0].setValue(eventDataMap["value"], "switch")
57 sendEvent(eventDataMap)
59 } else if (eventDataMap["name"] == "colorTemperature") {
60 if (eventDataMap["value"].toInteger() != colorTemperatues[0].colorTemperature) {
61 this.colorTemperature = eventDataMap["value"].toInteger()
62 colorTemperatues[0].setValue(eventDataMap["value"], "colorTemperature")
63 sendEvent(eventDataMap)
65 } else if (eventDataMap["name"] == "level") {
66 if (eventDataMap["value"].toInteger() != colorTemperatues[0].level) {
67 this.currentLevel = eventDataMap["value"].toInteger()
68 this.level = eventDataMap["value"].toInteger()
69 colorTemperatues[0].setValue(eventDataMap["value"], "level")
70 sendEvent(eventDataMap)
77 def setLevel(int level) {
78 if (level != this.level) {
79 this.currentLevel = level
81 colorTemperatues[0].setLevel(level)
85 def setColorTemperature(String colorTemperature) {
86 if (colorTemperature != this.colorTemperature) {
87 this.colorTemperature = colorTemperature
88 colorTemperatues[0].setColorTemperature(colorTemperature)
92 def on(String currentSwitch) {
93 if (currentSwitch != this.currentSwitch) {
94 this.currentSwitch = currentSwitch
95 colorTemperatues[0].on(currentSwitch)
99 def off(String currentSwitch) {
100 if (currentSwitch != this.currentSwitch) {
101 this.currentSwitch = currentSwitch
102 colorTemperatues[0].off(currentSwitch)
106 def currentValue(String deviceFeature) {
107 colorTemperatues[0].currentValue(deviceFeature)
110 def latestValue(String deviceFeature) {
111 colorTemperatues[0].latestValue(deviceFeature)