1 //Create a class for thermostat device
3 import Timer.SimulatedTimer
6 import gov.nasa.jpf.vm.Verify
8 public class Thermostats{
14 //When we have only one device
15 private String id = "thermostatID0"
16 private String label = "thermostat0"
17 private String displayName = "thermostat0"
18 private int temperature = 66
19 private int currentCoolingSetpoint = 70
20 private int currentHeatingSetpoint = 50
21 private int coolingSetpoint = 70
22 private int thermostatSetpoint = 60
23 private int heatingSetpoint = 50
24 private coolingSetpointRange = [70, 90]
25 private thermostatSetpointRange = [50, 70]
26 private heatingSetpointRange = [20, 50]
27 private supportedThermostatFanModes = ["auto", "fanCirculate", "circulate", "fanOn", "on"]
28 private supportedThermostatModes = ["auto", "cool", "emergencyHeat", "heat", "off"]
29 private String thermostatOperatingState = "cooling"
30 private String thermostatFanMode = "auto"
31 private String thermostatMode = "auto"
32 private String currentThermostatMode = "auto"
33 private String climateName = ""
35 Thermostats(Closure sendEvent, int deviceNumbers) {
36 this.sendEvent = sendEvent
37 this.timers = new SimulatedTimer()
38 this.deviceNumbers = deviceNumbers
41 def initTemperature = Verify.getIntFromList(60, 66, 70)
42 this.temperature = initTemperature
44 def initCoolingSetpoint = Verify.getIntFromList(70, 80, 90)
45 this.currentCoolingSetpoint = initCoolingSetpoint
46 this.coolingSetpoint = initCoolingSetpoint
48 def initHeatingSetpoint = Verify.getIntFromList(20, 35, 50)
49 this.currentHeatingSetpoint = initHeatingSetpoint
50 this.heatingSetpoint = initHeatingSetpoint
52 def initThermostatSetpoint = Verify.getIntFromList(50, 60, 70)
54 this.thermostatSetpoint = initThermostatSetpoint
56 this.currentHeatingSetpoint = initThermostatSetpoint
57 >>>>>>> e378d6a65b25030f8914dc97f04b81ddff351d9c
59 def initFanMode = Verify.getInt(0,4)
60 if (initFanMode == 0) {
61 this.thermostatFanMode = "auto"
62 } else if (initFanMode == 1) {
63 this.thermostatFanMode = "fanCirculate"
64 } else if (initFanMode == 2) {
65 this.thermostatFanMode = "circulate"
66 } else if (initFanMode == 3) {
67 this.thermostatFanMode = "fanOn"
69 this.thermostatFanMode = "on"
72 def initMode = Verify.getInt(0,4)
74 this.thermostatMode = "auto"
75 this.currentThermostatMode = "auto"
76 } else if (initMode == 1) {
77 this.thermostatMode = "cool"
78 this.currentThermostatMode = "cool"
79 } else if (initMode == 2) {
80 this.thermostatMode = "emergencyHeat"
81 this.currentThermostatMode = "emergencyHeat"
82 } else if (initMode == 3) {
83 this.thermostatMode = "heat"
84 this.currentThermostatMode = "heat"
86 this.thermostatMode = "off"
87 this.currentThermostatMode = "off"
90 thermostats.add(new Thermostat(sendEvent, id, label, displayName, this.temperature, this.currentCoolingSetpoint,
91 this.currentHeatingSetpoint, this.coolingSetpoint, this.thermostatSetpoint, this.heatingSetpoint, this.coolingSetpointRange,
92 this.thermostatSetpointRange, this.heatingSetpointRange, this.supportedThermostatFanModes, this.supportedThermostatModes,
93 this.thermostatOperatingState, this.thermostatFanMode, this.thermostatMode, this.climateName))
96 //Methods for closures
97 def count(Closure Input) {
98 thermostats.count(Input)
103 def each(Closure Input) {
104 thermostats.each(Input)
106 def find(Closure Input) {
107 thermostats.find(Input)
109 def collect(Closure Input) {
110 thermostats.collect(Input)
114 def setCoolingSetpoint(int coolingSetpoint) {
115 if (coolingSetpoint != this.coolingSetpoint) {
116 thermostats[0].setCoolingSetpoint(coolingSetpoint)
117 this.currentCoolingSetpoint = coolingSetpoint
118 this.coolingSetpoint = coolingSetpoint
122 def setHeatingSetpoint(int heatingSetpoint) {
123 if (heatingSetpoint != this.heatingSetpoint) {
124 thermostats[0].setHeatingSetpoint(heatingSetpoint)
125 this.currentHeatingSetpoint = heatingSetpoint
126 this.heatingSetpoint = heatingSetpoint
131 //Not implemented yet
134 def setThermostatFanMode(String thermostatFanMode) {
135 if (thermostatFanMode != this.thermostatFanMode) {
136 thermostats[0].setThermostatFanMode(thermostatFanMode)
137 this.thermostatFanMode = thermostatFanMode
141 def setThermostatMode(String thermostatMode) {
142 if (thermostatMode != this.thermostatMode) {
143 thermostats[0].setThermostatMode(thermostatMode)
144 this.thermostatMode = thermostatMode
145 this.currentThermostatMode = currentThermostatMode
150 if (thermostatMode != "cool") {
151 thermostats[0].cool()
152 this.thermostatMode = "cool"
153 this.currentThermostatMode = "cool"
158 if (thermostatMode != "heat") {
159 thermostats[0].heat()
160 this.thermostatMode = "heat"
161 this.currentThermostatMode = "heat"
166 if (thermostatMode != "auto") {
167 thermostats[0].auto()
168 this.thermostatMode = "auto"
169 this.currentThermostatMode = "auto"
174 if (thermostatMode != "off") {
176 this.thermostatMode = "off"
177 this.currentThermostatMode = "off"
181 def setClimate(String info, String givenClimateName) {
182 if (givenClimateName != climateName) {
183 thermostats[0].setClimate(info, givenClimateName)
184 this.climateName = givenClimateName
188 def setHold(String info1, int coolingSetpoint, int heatingSetpoint, String info2, String info3) {
189 if ((coolingSetpoint != this.coolingSetpoint) || (heatingSetpoint != this.heatingSetpoint)) {
190 thermostats[0].setHold(info1, coolingSetpoint, heatingSetpoint, info2, info3)
191 this.currentCoolingSetpoint = coolingSetpoint
192 this.coolingSetpoint = coolingSetpoint
193 this.currentHeatingSetpoint = heatingSetpoint
194 this.heatingSetpoint = heatingSetpoint
199 def setValue(LinkedHashMap eventDataMap) {
200 if (eventDataMap["name"] == "temperature") {
201 if (eventDataMap["value"] != thermostats[0].temperature) {
202 thermostats[0].setValue(eventDataMap["value"], "temperature")
203 this.temperature = thermostats[0].temperature
204 sendEvent(eventDataMap)
206 } else if (eventDataMap["name"] == "heatingSetpoint") {
207 if (eventDataMap["value"] != thermostats[0].heatingSetpoint) {
208 thermostats[0].setValue(eventDataMap["value"], "heatingSetpoint")
209 this.heatingSetpoint = thermostats[0].heatingSetpoint
210 sendEvent(eventDataMap)
212 } else if (eventDataMap["name"] == "coolingSetpoint") {
213 if (eventDataMap["value"] != thermostats[0].coolingSetpoint) {
214 thermostats[0].setValue(eventDataMap["value"], "coolingSetpoint")
215 this.coolingSetpoint = thermostats[0].coolingSetpoint
216 sendEvent(eventDataMap)
218 } else if (eventDataMap["name"] == "thermostatSetpoint") {
219 if (eventDataMap["value"] != thermostats[0].thermostatSetpoint) {
220 thermostats[0].setValue(eventDataMap["value"], "thermostatSetpoint")
221 this.thermostatSetpoint = thermostats[0].thermostatSetpoint
222 sendEvent(eventDataMap)
224 } else if (eventDataMap["name"] == "thermostatMode") {
225 if (eventDataMap["value"] != thermostats[0].thermostatMode) {
226 thermostats[0].setValue(eventDataMap["value"], "thermostatMode")
227 this.thermostatMode = thermostats[0].thermostatMode
228 this.currentThermostatMode = thermostats[0].currentThermostatMode
229 sendEvent(eventDataMap)
231 } else if (eventDataMap["name"] == "thermostatFanMode") {
232 if (eventDataMap["value"] != thermostats[0].thermostatFanMode) {
233 thermostats[0].setValue(eventDataMap["value"], "thermostatFanMode")
234 this.thermostatFanMode = thermostats[0].thermostatFanMode
235 sendEvent(eventDataMap)
237 } else if (eventDataMap["name"] == "thermostatOperatingState") {
238 if (eventDataMap["value"] != thermostats[0].thermostatOperatingState) {
239 thermostats[0].setValue(eventDataMap["value"], "thermostatOperatingState")
240 this.thermostatOperatingState = thermostats[0].thermostatOperatingState
241 sendEvent(eventDataMap)