edits and remove generated flag from repo
[smartthings-infrastructure.git] / ColorTemperature / ColorTemperatures.groovy
1 //Create a class for color temperature
2 package ColorTemperature
3 import Timer.SimulatedTimer
4
5 //JPF's Verify API
6 import gov.nasa.jpf.vm.Verify
7
8 public class ColorTemperatures {
9         private int deviceNumbers
10         private List colorTemperatues
11         def sendEvent
12
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
21         
22
23         ColorTemperatures(Closure sendEvent, int deviceNumbers) {
24                 this.sendEvent = sendEvent
25                 this.deviceNumbers = deviceNumbers
26                 this.colorTemperatues = []
27
28                 colorTemperatues.add(new ColorTemperature(sendEvent, id, label, displayName, this.level, this.currentSwitch, this.colorTemperature))
29         }
30
31         //Methods for closures
32         def count(Closure Input) {
33                 colorTemperatues.count(Input)
34         }
35         def size() {
36                 colorTemperatues.size()
37         }
38         def each(Closure Input) {
39                 colorTemperatues.each(Input)
40         }
41         def find(Closure Input) {
42                 colorTemperatues.find(Input)
43         }
44         def sort(Closure Input) {
45                 colorTemperatues.sort(Input)
46         }
47         def collect(Closure Input) {
48                 colorTemperatues.collect(Input)
49         }
50
51         //By model checker
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)
58                         }
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)
64                         }
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)
71                         }
72                 }
73         }
74
75
76         //methods
77         def setLevel(int level) {
78                 if (level != this.level) {
79                         this.currentLevel = level
80                         this.level = level
81                         colorTemperatues[0].setLevel(level)
82                 }
83         }
84
85         def setColorTemperature(String colorTemperature) {
86                 if (colorTemperature != this.colorTemperature) {
87                         this.colorTemperature = colorTemperature
88                         colorTemperatues[0].setColorTemperature(colorTemperature)                       
89                 }
90         }
91
92         def on(String currentSwitch) {
93                 if (currentSwitch != this.currentSwitch) {
94                         this.currentSwitch = currentSwitch
95                         colorTemperatues[0].on(currentSwitch)                   
96                 }
97         }
98
99         def off(String currentSwitch) {
100                 if (currentSwitch != this.currentSwitch) {
101                         this.currentSwitch = currentSwitch
102                         colorTemperatues[0].off(currentSwitch)                  
103                 }
104         }
105
106         def currentValue(String deviceFeature) {
107                 colorTemperatues[0].currentValue(deviceFeature)
108         }
109
110         def latestValue(String deviceFeature) {
111                 colorTemperatues[0].latestValue(deviceFeature)
112         }       
113
114         def getAt(int ix) {
115                 colorTemperatues[ix]
116         }
117 }