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)
53 this.thermostatSetpoint = initThermostatSetpoint
55 def initFanMode = Verify.getInt(0,4)
56 if (initFanMode == 0) {
57 this.thermostatFanMode = "auto"
58 } else if (initFanMode == 1) {
59 this.thermostatFanMode = "fanCirculate"
60 } else if (initFanMode == 2) {
61 this.thermostatFanMode = "circulate"
62 } else if (initFanMode == 3) {
63 this.thermostatFanMode = "fanOn"
65 this.thermostatFanMode = "on"
68 def initMode = Verify.getInt(0,4)
70 this.thermostatMode = "auto"
71 this.currentThermostatMode = "auto"
72 } else if (initMode == 1) {
73 this.thermostatMode = "cool"
74 this.currentThermostatMode = "cool"
75 } else if (initMode == 2) {
76 this.thermostatMode = "emergencyHeat"
77 this.currentThermostatMode = "emergencyHeat"
78 } else if (initMode == 3) {
79 this.thermostatMode = "heat"
80 this.currentThermostatMode = "heat"
82 this.thermostatMode = "off"
83 this.currentThermostatMode = "off"
86 thermostats.add(new Thermostat(sendEvent, id, label, displayName, this.temperature, this.currentCoolingSetpoint,
87 this.currentHeatingSetpoint, this.coolingSetpoint, this.thermostatSetpoint, this.heatingSetpoint, this.coolingSetpointRange,
88 this.thermostatSetpointRange, this.heatingSetpointRange, this.supportedThermostatFanModes, this.supportedThermostatModes,
89 this.thermostatOperatingState, this.thermostatFanMode, this.thermostatMode, this.climateName))
92 //Methods for closures
93 def count(Closure Input) {
94 thermostats.count(Input)
99 def each(Closure Input) {
100 thermostats.each(Input)
102 def find(Closure Input) {
103 thermostats.find(Input)
105 def collect(Closure Input) {
106 thermostats.collect(Input)
110 def setCoolingSetpoint(int coolingSetpoint) {
111 if (coolingSetpoint != this.coolingSetpoint) {
112 thermostats[0].setCoolingSetpoint(coolingSetpoint)
113 this.currentCoolingSetpoint = coolingSetpoint
114 this.coolingSetpoint = coolingSetpoint
118 def setHeatingSetpoint(int heatingSetpoint) {
119 if (heatingSetpoint != this.heatingSetpoint) {
120 thermostats[0].setHeatingSetpoint(heatingSetpoint)
121 this.currentHeatingSetpoint = heatingSetpoint
122 this.heatingSetpoint = heatingSetpoint
127 //Not implemented yet
130 def setThermostatFanMode(String thermostatFanMode) {
131 if (thermostatFanMode != this.thermostatFanMode) {
132 thermostats[0].setThermostatFanMode(thermostatFanMode)
133 this.thermostatFanMode = thermostatFanMode
137 def setThermostatMode(String thermostatMode) {
138 if (thermostatMode != this.thermostatMode) {
139 thermostats[0].setThermostatMode(thermostatMode)
140 this.thermostatMode = thermostatMode
141 this.currentThermostatMode = currentThermostatMode
146 if (thermostatMode != "cool") {
147 thermostats[0].cool()
148 this.thermostatMode = "cool"
149 this.currentThermostatMode = "cool"
154 if (thermostatMode != "heat") {
155 thermostats[0].heat()
156 this.thermostatMode = "heat"
157 this.currentThermostatMode = "heat"
162 if (thermostatMode != "auto") {
163 thermostats[0].auto()
164 this.thermostatMode = "auto"
165 this.currentThermostatMode = "auto"
170 if (thermostatMode != "off") {
172 this.thermostatMode = "off"
173 this.currentThermostatMode = "off"
177 def setClimate(String info, String givenClimateName) {
178 if (givenClimateName != climateName) {
179 thermostats[0].setClimate(info, givenClimateName)
180 this.climateName = givenClimateName
184 def setHold(String info1, int coolingSetpoint, int heatingSetpoint, String info2, String info3) {
185 if ((coolingSetpoint != this.coolingSetpoint) || (heatingSetpoint != this.heatingSetpoint)) {
186 thermostats[0].setHold(info1, coolingSetpoint, heatingSetpoint, info2, info3)
187 this.currentCoolingSetpoint = coolingSetpoint
188 this.coolingSetpoint = coolingSetpoint
189 this.currentHeatingSetpoint = heatingSetpoint
190 this.heatingSetpoint = heatingSetpoint
195 def setValue(LinkedHashMap eventDataMap) {
196 if (eventDataMap["name"] == "temperature") {
197 if (eventDataMap["value"] != thermostats[0].temperature) {
198 thermostats[0].setValue(eventDataMap["value"], "temperature")
199 this.temperature = thermostats[0].temperature
200 sendEvent(eventDataMap)
202 } else if (eventDataMap["name"] == "heatingSetpoint") {
203 if (eventDataMap["value"] != thermostats[0].heatingSetpoint) {
204 thermostats[0].setValue(eventDataMap["value"], "heatingSetpoint")
205 this.heatingSetpoint = thermostats[0].heatingSetpoint
206 sendEvent(eventDataMap)
208 } else if (eventDataMap["name"] == "coolingSetpoint") {
209 if (eventDataMap["value"] != thermostats[0].coolingSetpoint) {
210 thermostats[0].setValue(eventDataMap["value"], "coolingSetpoint")
211 this.coolingSetpoint = thermostats[0].coolingSetpoint
212 sendEvent(eventDataMap)
214 } else if (eventDataMap["name"] == "thermostatSetpoint") {
215 if (eventDataMap["value"] != thermostats[0].thermostatSetpoint) {
216 thermostats[0].setValue(eventDataMap["value"], "thermostatSetpoint")
217 this.thermostatSetpoint = thermostats[0].thermostatSetpoint
218 sendEvent(eventDataMap)
220 } else if (eventDataMap["name"] == "thermostatMode") {
221 if (eventDataMap["value"] != thermostats[0].thermostatMode) {
222 thermostats[0].setValue(eventDataMap["value"], "thermostatMode")
223 this.thermostatMode = thermostats[0].thermostatMode
224 this.currentThermostatMode = thermostats[0].currentThermostatMode
225 sendEvent(eventDataMap)
227 } else if (eventDataMap["name"] == "thermostatFanMode") {
228 if (eventDataMap["value"] != thermostats[0].thermostatFanMode) {
229 thermostats[0].setValue(eventDataMap["value"], "thermostatFanMode")
230 this.thermostatFanMode = thermostats[0].thermostatFanMode
231 sendEvent(eventDataMap)
233 } else if (eventDataMap["name"] == "thermostatOperatingState") {
234 if (eventDataMap["value"] != thermostats[0].thermostatOperatingState) {
235 thermostats[0].setValue(eventDataMap["value"], "thermostatOperatingState")
236 this.thermostatOperatingState = thermostats[0].thermostatOperatingState
237 sendEvent(eventDataMap)