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, 70)
50 this.temperature = initTemperature
51 this.currentTemperature = initTemperature
53 def initCoolingSetpoint = Verify.getIntFromList(70, 80, 90)
54 this.currentCoolingSetpoint = initCoolingSetpoint
55 this.coolingSetpoint = initCoolingSetpoint
57 def initHeatingSetpoint = Verify.getIntFromList(20, 35, 50)
58 this.currentHeatingSetpoint = initHeatingSetpoint
59 this.heatingSetpoint = initHeatingSetpoint
61 def initThermostatSetpoint = Verify.getIntFromList(50, 60, 70)
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 thermostats[0].setHold(info1, coolingSetpoint, heatingSetpoint, info2, info3)
235 def setValue(LinkedHashMap eventDataMap) {
236 if (eventDataMap["name"] == "temperature") {
237 if (eventDataMap["value"].toInteger() != thermostats[0].temperature) {
238 this.temperature = eventDataMap["value"].toInteger()
239 this.currentTemperature = eventDataMap["value"].toInteger()
240 thermostats[0].setValue(eventDataMap["value"], "temperature")
241 sendEvent(eventDataMap)
243 } else if (eventDataMap["name"] == "heatingSetpoint") {
244 if (eventDataMap["value"].toInteger() != thermostats[0].heatingSetpoint) {
245 this.latestHeatingSetpoint = eventDataMap["value"].toInteger()
246 this.heatingSetpoint = eventDataMap["value"].toInteger()
247 thermostats[0].setValue(eventDataMap["value"], "heatingSetpoint")
248 sendEvent(eventDataMap)
250 } else if (eventDataMap["name"] == "coolingSetpoint") {
251 if (eventDataMap["value"].toInteger() != thermostats[0].coolingSetpoint) {
252 this.latestCoolingSetPoint = eventDataMap["value"].toInteger()
253 this.coolingSetpoint = eventDataMap["value"].toInteger()
254 thermostats[0].setValue(eventDataMap["value"], "coolingSetpoint")
255 sendEvent(eventDataMap)
257 } else if (eventDataMap["name"] == "thermostatSetpoint") {
258 if (eventDataMap["value"].toInteger() != thermostats[0].thermostatSetpoint) {
259 this.latestThermostatSetpoint = eventDataMap["value"].toInteger()
260 this.thermostatSetpoint = eventDataMap["value"].toInteger()
261 thermostats[0].setValue(eventDataMap["value"], "thermostatSetpoint")
262 sendEvent(eventDataMap)
264 } else if (eventDataMap["name"] == "thermostatMode") {
265 if (eventDataMap["value"] != thermostats[0].thermostatMode) {
266 this.thermostatLatestMode = eventDataMap["value"]
267 this.thermostatMode = eventDataMap["value"]
268 this.currentThermostatMode = eventDataMap["value"]
269 thermostats[0].setValue(eventDataMap["value"], "thermostatMode")
270 sendEvent(eventDataMap)
272 } else if (eventDataMap["name"] == "thermostatFanMode") {
273 if (eventDataMap["value"] != thermostats[0].thermostatFanMode) {
274 this.thermostatLatestFanMode = eventDataMap["value"]
275 this.thermostatFanMode = eventDataMap["value"]
276 thermostats[0].setValue(eventDataMap["value"], "thermostatFanMode")
277 sendEvent(eventDataMap)
279 } else if (eventDataMap["name"] == "thermostatOperatingState") {
280 if (eventDataMap["value"] != thermostats[0].thermostatOperatingState) {
281 this.thermostatLatestOperatingState = eventDataMap["value"]
282 this.thermostatOperatingState = eventDataMap["value"]
283 thermostats[0].setValue(eventDataMap["value"], "thermostatOperatingState")
284 sendEvent(eventDataMap)
289 def currentValue(String deviceFeature) {
290 thermostats[0].currentValue(deviceFeature)
293 def latestValue(String deviceFeature) {
294 thermostats[0].latestValue(deviceFeature)