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 currentTemperature = 66
20 private int currentCoolingSetpoint = 70
21 private int currentHeatingSetpoint = 50
22 private int coolingSetpoint = 70
23 private int thermostatSetpoint = 60
24 private int heatingSetpoint = 50
25 private coolingSetpointRange = [70, 90]
26 private thermostatSetpointRange = [50, 70]
27 private heatingSetpointRange = [20, 50]
28 private supportedThermostatFanModes = ["auto", "fanCirculate", "circulate", "fanOn", "on"]
29 private supportedThermostatModes = ["auto", "cool", "emergencyHeat", "heat", "off"]
30 private String thermostatOperatingState = "cooling"
31 private String thermostatFanMode = "auto"
32 private String thermostatMode = "auto"
33 private String currentThermostatMode = "auto"
34 private String climateName = ""
35 private String thermostatLatestMode = "auto"
36 private String thermostatLatestOperatingState = "cooling"
37 private String thermostatLatestFanMode = "auto"
38 private int latestCoolingSetPoint = 70
39 private int latestThermostatSetPoint = 60
40 private int latestHeatingSetPoint = 50
43 Thermostats(Closure sendEvent, int deviceNumbers) {
44 this.sendEvent = sendEvent
45 this.timers = new SimulatedTimer()
46 this.deviceNumbers = deviceNumbers
49 def initTemperature = Verify.getIntFromList(60, 66)
50 this.temperature = initTemperature
51 this.currentTemperature = initTemperature
53 def initCoolingSetpoint = Verify.getIntFromList(70, 80)
54 this.currentCoolingSetpoint = initCoolingSetpoint
55 this.coolingSetpoint = initCoolingSetpoint
57 def initHeatingSetpoint = Verify.getIntFromList(35, 50)
58 this.currentHeatingSetpoint = initHeatingSetpoint
59 this.heatingSetpoint = initHeatingSetpoint
61 def initThermostatSetpoint = Verify.getIntFromList(50, 60)
62 this.thermostatSetpoint = initThermostatSetpoint
64 def initFanMode = Verify.getInt(0,4)
65 if (initFanMode == 0) {
66 this.thermostatFanMode = "auto"
67 this.thermostatLatestFanMode = "auto"
68 } else if (initFanMode == 1) {
69 this.thermostatFanMode = "fanCirculate"
70 this.thermostatLatestFanMode = "fanCirculate"
71 } else if (initFanMode == 2) {
72 this.thermostatFanMode = "circulate"
73 this.thermostatLatestFanMode = "circulate"
74 } else if (initFanMode == 3) {
75 this.thermostatFanMode = "fanOn"
76 this.thermostatLatestFanMode = "fanOn"
78 this.thermostatFanMode = "on"
79 this.thermostatLatestFanMode = "on"
82 def initMode = Verify.getInt(0,4)
84 this.thermostatMode = "auto"
85 this.currentThermostatMode = "auto"
86 this.thermostatLatestMode = "auto"
87 } else if (initMode == 1) {
88 this.thermostatMode = "cool"
89 this.currentThermostatMode = "cool"
90 this.thermostatLatestMode = "cool"
91 } else if (initMode == 2) {
92 this.thermostatMode = "emergencyHeat"
93 this.currentThermostatMode = "emergencyHeat"
94 this.thermostatLatestMode = "emergencyHeat"
95 } else if (initMode == 3) {
96 this.thermostatMode = "heat"
97 this.currentThermostatMode = "heat"
98 this.thermostatLatestMode = "heat"
100 this.thermostatMode = "off"
101 this.currentThermostatMode = "off"
102 this.thermostatLatestMode = "off"
105 thermostats.add(new Thermostat(sendEvent, id, label, displayName, this.temperature, this.currentCoolingSetpoint,
106 this.currentHeatingSetpoint, this.coolingSetpoint, this.thermostatSetpoint, this.heatingSetpoint, this.coolingSetpointRange,
107 this.thermostatSetpointRange, this.heatingSetpointRange, this.supportedThermostatFanModes, this.supportedThermostatModes,
108 this.thermostatOperatingState, this.thermostatFanMode, this.thermostatMode, this.climateName,
109 this.thermostatLatestMode, this.thermostatLatestOperatingState, this.thermostatLatestFanMode, this.latestCoolingSetPoint,
110 this.latestThermostatSetPoint, this.latestHeatingSetPoint))
113 //Methods for closures
114 def count(Closure Input) {
115 thermostats.count(Input)
120 def each(Closure Input) {
121 thermostats.each(Input)
123 def find(Closure Input) {
124 thermostats.find(Input)
126 def sort(Closure Input) {
127 thermostats.sort(Input)
129 def collect(Closure Input) {
130 thermostats.collect(Input)
134 def setCoolingSetpoint(int coolingSetpoint) {
135 if (coolingSetpoint != this.coolingSetpoint) {
136 this.latestCoolingSetPoint = coolingSetpoint
137 this.currentCoolingSetpoint = coolingSetpoint
138 this.coolingSetpoint = coolingSetpoint
139 thermostats[0].setCoolingSetpoint(coolingSetpoint)
143 def setCoolingSetpoint(String coolingSetpoint) {
144 setCoolingSetpoint(coolingSetpoint.toInteger())
147 def setHeatingSetpoint(int heatingSetpoint) {
148 if (heatingSetpoint != this.heatingSetpoint) {
149 this.latestHeatingSetPoint = heatingSetpoint
150 this.currentHeatingSetpoint = heatingSetpoint
151 this.heatingSetpoint = heatingSetpoint
152 thermostats[0].setHeatingSetpoint(heatingSetpoint)
156 def setHeatingSetpoint(String heatingSetpoint) {
157 setHeatingSetpoint(heatingSetpoint.toInteger())
161 //Not implemented yet
164 def setThermostatFanMode(String thermostatFanMode) {
165 if (thermostatFanMode != this.thermostatFanMode) {
166 this.thermostatLatestFanMode = thermostatFanMode
167 this.thermostatFanMode = thermostatFanMode
168 thermostats[0].setThermostatFanMode(thermostatFanMode)
172 def setThermostatMode(String thermostatMode) {
173 if (thermostatMode != this.thermostatMode) {
174 this.thermostatLatestMode = thermostatMode
175 this.thermostatMode = thermostatMode
176 this.currentThermostatMode = currentThermostatMode
177 thermostats[0].setThermostatMode(thermostatMode)
182 if (thermostatMode != "cool") {
183 this.thermostatLatestMode = "cool"
184 this.thermostatMode = "cool"
185 this.currentThermostatMode = "cool"
186 thermostats[0].cool()
191 if (thermostatMode != "heat") {
192 this.thermostatLatestMode = "heat"
193 this.thermostatMode = "heat"
194 this.currentThermostatMode = "heat"
195 thermostats[0].heat()
200 if (thermostatMode != "auto") {
201 this.thermostatLatestMode = "auto"
202 this.thermostatMode = "auto"
203 this.currentThermostatMode = "auto"
204 thermostats[0].auto()
209 if (thermostatMode != "off") {
210 this.thermostatLatestMode = "off"
211 this.thermostatMode = "off"
212 this.currentThermostatMode = "off"
217 def setClimate(String info, String givenClimateName) {
218 if (givenClimateName != climateName) {
219 this.climateName = givenClimateName
220 thermostats[0].setClimate(info, givenClimateName)
224 def setHold(String info1, int coolingSetpoint, int heatingSetpoint, String info2, String info3) {
225 if ((coolingSetpoint != this.coolingSetpoint) || (heatingSetpoint != this.heatingSetpoint)) {
226 this.currentCoolingSetpoint = coolingSetpoint
227 this.coolingSetpoint = coolingSetpoint
228 this.currentHeatingSetpoint = heatingSetpoint
229 this.heatingSetpoint = heatingSetpoint
230 this.latestCoolingSetPoint = coolingSetpoint
231 this.latestHeatingSetPoint = heatingSetpoint
232 thermostats[0].setHold(info1, coolingSetpoint, heatingSetpoint, info2, info3)
237 def setValue(LinkedHashMap eventDataMap) {
238 if (eventDataMap["name"] == "temperature") {
239 if (eventDataMap["value"].toInteger() != thermostats[0].temperature) {
240 this.temperature = eventDataMap["value"].toInteger()
241 this.currentTemperature = eventDataMap["value"].toInteger()
242 thermostats[0].setValue(eventDataMap["value"], "temperature")
243 sendEvent(eventDataMap)
245 } else if (eventDataMap["name"] == "heatingSetpoint") {
246 if (eventDataMap["value"].toInteger() != thermostats[0].heatingSetpoint) {
247 this.latestHeatingSetPoint = eventDataMap["value"].toInteger()
248 this.heatingSetpoint = eventDataMap["value"].toInteger()
249 thermostats[0].setValue(eventDataMap["value"], "heatingSetpoint")
250 sendEvent(eventDataMap)
252 } else if (eventDataMap["name"] == "coolingSetpoint") {
253 if (eventDataMap["value"].toInteger() != thermostats[0].coolingSetpoint) {
254 this.latestCoolingSetPoint = eventDataMap["value"].toInteger()
255 this.coolingSetpoint = eventDataMap["value"].toInteger()
256 thermostats[0].setValue(eventDataMap["value"], "coolingSetpoint")
257 sendEvent(eventDataMap)
259 } else if (eventDataMap["name"] == "thermostatSetpoint") {
260 if (eventDataMap["value"].toInteger() != thermostats[0].thermostatSetpoint) {
261 this.latestThermostatSetPoint = eventDataMap["value"].toInteger()
262 this.thermostatSetpoint = eventDataMap["value"].toInteger()
263 thermostats[0].setValue(eventDataMap["value"], "thermostatSetpoint")
264 sendEvent(eventDataMap)
266 } else if (eventDataMap["name"] == "thermostatMode") {
267 if (eventDataMap["value"] != thermostats[0].thermostatMode) {
268 this.thermostatLatestMode = eventDataMap["value"]
269 this.thermostatMode = eventDataMap["value"]
270 this.currentThermostatMode = eventDataMap["value"]
271 thermostats[0].setValue(eventDataMap["value"], "thermostatMode")
272 sendEvent(eventDataMap)
274 } else if (eventDataMap["name"] == "thermostatFanMode") {
275 if (eventDataMap["value"] != thermostats[0].thermostatFanMode) {
276 this.thermostatLatestFanMode = eventDataMap["value"]
277 this.thermostatFanMode = eventDataMap["value"]
278 thermostats[0].setValue(eventDataMap["value"], "thermostatFanMode")
279 sendEvent(eventDataMap)
281 } else if (eventDataMap["name"] == "thermostatOperatingState") {
282 if (eventDataMap["value"] != thermostats[0].thermostatOperatingState) {
283 this.thermostatLatestOperatingState = eventDataMap["value"]
284 this.thermostatOperatingState = eventDataMap["value"]
285 thermostats[0].setValue(eventDataMap["value"], "thermostatOperatingState")
286 sendEvent(eventDataMap)
291 def currentValue(String deviceFeature) {
292 thermostats[0].currentValue(deviceFeature)
295 def latestValue(String deviceFeature) {
296 thermostats[0].latestValue(deviceFeature)