//Create a class for color temperature
package ColorTemperature
-import Timer.SimulatedTimer
+import SmartThing.SmartThings
-//JPF's Verify API
-import gov.nasa.jpf.vm.Verify
+//Importing mutable integer class
+import MutableInteger.MutableInteger
-public class ColorTemperatures {
- private int deviceNumbers
- private List colorTemperatues
- def sendEvent
+public class ColorTemperatures extends SmartThings {
+ List colorTemperatues = new ArrayList()
- //For one device(We cannot have obj.id)-> We should have obj[0].id
- private String id = "colorTemperatureID0"
- private String label = "colorTemperature0"
- private String displayName = "colorTemperature0"
- private String currentSwitch = "off"
- private int level = 50
- private int currentLevel = 50
- private int colorTemperature = 15000
-
+ ColorTemperatures(Closure sendEvent, boolean init) {
+ // Only initialize one time since we only have one device for each capability
+ colorTemperatues = smartThings
- ColorTemperatures(Closure sendEvent, int deviceNumbers) {
- this.sendEvent = sendEvent
- this.deviceNumbers = deviceNumbers
- this.colorTemperatues = []
+ // Initialization
+ StringBuilder id = new StringBuilder("colorTemperatureID0")
+ StringBuilder label = new StringBuilder("colorTemperature")
+ StringBuilder displayName = new StringBuilder("colorTemperature0")
+ MutableInteger colorTemperatue = new MutableInteger()
- colorTemperatues.add(new ColorTemperature(sendEvent, id, label, displayName, this.level, this.currentSwitch, this.colorTemperature))
- }
+ if (init)
+ colorTemperature = 10000
+ else
+ colorTemperatues = 15000
- //Methods for closures
- def count(Closure Input) {
- colorTemperatues.count(Input)
- }
- def size() {
- colorTemperatues.size()
- }
- def each(Closure Input) {
- colorTemperatues.each(Input)
- }
- def find(Closure Input) {
- colorTemperatues.find(Input)
- }
- def sort(Closure Input) {
- colorTemperatues.sort(Input)
+ colorTemperatues.add(new ColorTemperature(sendEvent, id, label, displayName, colorTemperature))
}
- def collect(Closure Input) {
- colorTemperatues.collect(Input)
- }
-
- //By model checker
- def setValue(LinkedHashMap eventDataMap) {
- if (eventDataMap["name"] == "switch") {
- if (eventDataMap["value"] != colorTemperatues[0].currentSwitch) {
- this.currentSwitch = eventDataMap["value"]
- colorTemperatues[0].setValue(eventDataMap["value"], "switch")
- sendEvent(eventDataMap)
- }
- } else if (eventDataMap["name"] == "colorTemperature") {
- if (eventDataMap["value"].toInteger() != colorTemperatues[0].colorTemperature) {
- this.colorTemperature = eventDataMap["value"].toInteger()
- colorTemperatues[0].setValue(eventDataMap["value"], "colorTemperature")
- sendEvent(eventDataMap)
- }
- } else if (eventDataMap["name"] == "level") {
- if (eventDataMap["value"].toInteger() != colorTemperatues[0].level) {
- this.currentLevel = eventDataMap["value"].toInteger()
- this.level = eventDataMap["value"].toInteger()
- colorTemperatues[0].setValue(eventDataMap["value"], "level")
- sendEvent(eventDataMap)
- }
- }
- }
-
-
- //methods
- def setLevel(int level) {
- if (level != this.level) {
- this.currentLevel = level
- this.level = level
- colorTemperatues[0].setLevel(level)
- }
- }
-
- def setColorTemperature(String colorTemperature) {
- if (colorTemperature != this.colorTemperature) {
- this.colorTemperature = colorTemperature
- colorTemperatues[0].setColorTemperature(colorTemperature)
- }
- }
-
- def on(String currentSwitch) {
- if (currentSwitch != this.currentSwitch) {
- this.currentSwitch = currentSwitch
- colorTemperatues[0].on(currentSwitch)
- }
- }
-
- def off(String currentSwitch) {
- if (currentSwitch != this.currentSwitch) {
- this.currentSwitch = currentSwitch
- colorTemperatues[0].off(currentSwitch)
- }
- }
-
- def currentValue(String deviceFeature) {
- colorTemperatues[0].currentValue(deviceFeature)
+
+ // Methods to set values
+ def setColorTemperature(int newValue) {
+ colorTemperatues[0].setColorTemperature(newValue)
}
- def latestValue(String deviceFeature) {
- colorTemperatues[0].latestValue(deviceFeature)
- }
-
- def getAt(int ix) {
- colorTemperatues[ix]
+ // Methods to return values
+ def getCurrentColorTemperature() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(colorTemperatues[0].getCurrentColorTemperature())
+ return tmpValues
}
}