1 //Create a class for thermostat device
3 import Timer.SimulatedTimer
5 public class Thermostats{
11 //When we have only one device
12 private String id = "thermostatID0"
13 private String label = "thermostat0"
14 private String displayName = "thermostat0"
15 private int temperature = 66
16 private int currentTemperature = 66
17 private int currentCoolingSetpoint = 70
18 private int currentHeatingSetpoint = 50
19 private int coolingSetpoint = 70
20 private int thermostatSetpoint = 60
21 private int heatingSetpoint = 50
22 private coolingSetpointRange = [70, 90]
23 private thermostatSetpointRange = [50, 70]
24 private heatingSetpointRange = [20, 50]
25 private supportedThermostatFanModes = ["auto", "fanCirculate", "circulate", "fanOn", "on"]
26 private supportedThermostatModes = ["auto", "cool", "emergencyHeat", "heat", "off"]
27 private String thermostatOperatingState = "cooling"
28 private String thermostatFanMode = "auto"
29 private String thermostatMode = "auto"
30 private String currentThermostatMode = "auto"
31 private String climateName = ""
32 private String thermostatLatestMode = "auto"
33 private String thermostatLatestOperatingState = "cooling"
34 private String thermostatLatestFanMode = "auto"
35 private int latestCoolingSetPoint = 70
36 private int latestThermostatSetPoint = 60
37 private int latestHeatingSetPoint = 50
40 Thermostats(Closure sendEvent, int deviceNumbers, boolean init) {
41 this.sendEvent = sendEvent
42 this.timers = new SimulatedTimer()
43 this.deviceNumbers = deviceNumbers
48 this.currentTemperature = 60
49 this.currentCoolingSetpoint = 70
50 this.coolingSetpoint = 70
51 this.currentHeatingSetpoint = 35
52 this.heatingSetpoint = 35
53 this.thermostatSetpoint = 50
54 this.thermostatFanMode = "auto"
55 this.thermostatLatestFanMode = "auto"
56 this.thermostatMode = "auto"
57 this.currentThermostatMode = "auto"
58 this.thermostatLatestMode = "auto"
61 this.currentTemperature = 66
62 this.currentCoolingSetpoint = 80
63 this.coolingSetpoint = 80
64 this.currentHeatingSetpoint = 50
65 this.heatingSetpoint = 50
66 this.thermostatSetpoint = 60
67 this.thermostatFanMode = "circulate"
68 this.thermostatLatestFanMode = "circulate"
69 this.thermostatMode = "off"
70 this.currentThermostatMode = "off"
71 this.thermostatLatestMode = "off"
73 thermostats.add(new Thermostat(sendEvent, id, label, displayName, this.temperature, this.currentCoolingSetpoint,
74 this.currentHeatingSetpoint, this.coolingSetpoint, this.thermostatSetpoint, this.heatingSetpoint, this.coolingSetpointRange,
75 this.thermostatSetpointRange, this.heatingSetpointRange, this.supportedThermostatFanModes, this.supportedThermostatModes,
76 this.thermostatOperatingState, this.thermostatFanMode, this.thermostatMode, this.climateName,
77 this.thermostatLatestMode, this.thermostatLatestOperatingState, this.thermostatLatestFanMode, this.latestCoolingSetPoint,
78 this.latestThermostatSetPoint, this.latestHeatingSetPoint))
81 //Methods for closures
82 def count(Closure Input) {
83 thermostats.count(Input)
88 def each(Closure Input) {
89 thermostats.each(Input)
91 def find(Closure Input) {
92 thermostats.find(Input)
94 def sort(Closure Input) {
95 thermostats.sort(Input)
97 def collect(Closure Input) {
98 thermostats.collect(Input)
102 def setCoolingSetpoint(int coolingSetpoint) {
103 if (coolingSetpoint != this.coolingSetpoint) {
104 this.latestCoolingSetPoint = coolingSetpoint
105 this.currentCoolingSetpoint = coolingSetpoint
106 this.coolingSetpoint = coolingSetpoint
107 thermostats[0].setCoolingSetpoint(coolingSetpoint)
111 def setCoolingSetpoint(String coolingSetpoint) {
112 setCoolingSetpoint(coolingSetpoint.toInteger())
115 def setHeatingSetpoint(int heatingSetpoint) {
116 if (heatingSetpoint != this.heatingSetpoint) {
117 this.latestHeatingSetPoint = heatingSetpoint
118 this.currentHeatingSetpoint = heatingSetpoint
119 this.heatingSetpoint = heatingSetpoint
120 thermostats[0].setHeatingSetpoint(heatingSetpoint)
124 def setHeatingSetpoint(String heatingSetpoint) {
125 setHeatingSetpoint(heatingSetpoint.toInteger())
129 //Not implemented yet
132 def setThermostatFanMode(String thermostatFanMode) {
133 if (thermostatFanMode != this.thermostatFanMode) {
134 this.thermostatLatestFanMode = thermostatFanMode
135 this.thermostatFanMode = thermostatFanMode
136 thermostats[0].setThermostatFanMode(thermostatFanMode)
140 def setThermostatMode(String thermostatMode) {
141 if (thermostatMode != this.thermostatMode) {
142 this.thermostatLatestMode = thermostatMode
143 this.thermostatMode = thermostatMode
144 this.currentThermostatMode = currentThermostatMode
145 thermostats[0].setThermostatMode(thermostatMode)
150 if (thermostatMode != "cool") {
151 this.thermostatLatestMode = "cool"
152 this.thermostatMode = "cool"
153 this.currentThermostatMode = "cool"
154 thermostats[0].cool()
159 if (thermostatMode != "heat") {
160 this.thermostatLatestMode = "heat"
161 this.thermostatMode = "heat"
162 this.currentThermostatMode = "heat"
163 thermostats[0].heat()
168 if (thermostatMode != "auto") {
169 this.thermostatLatestMode = "auto"
170 this.thermostatMode = "auto"
171 this.currentThermostatMode = "auto"
172 thermostats[0].auto()
176 def emergencyHeat() {
177 if (thermostatMode != "emergencyHeat") {
178 this.thermostatLatestMode = "emergencyHeat"
179 this.thermostatMode = "emergencyHeat"
180 this.currentThermostatMode = "emergencyHeat"
181 thermostats[0].emergencyHeat()
186 if (thermostatMode != "off") {
187 this.thermostatLatestMode = "off"
188 this.thermostatMode = "off"
189 this.currentThermostatMode = "off"
194 def setClimate(String info, String givenClimateName) {
195 if (givenClimateName != climateName) {
196 this.climateName = givenClimateName
197 thermostats[0].setClimate(info, givenClimateName)
201 def setHold(String info1, int coolingSetpoint, int heatingSetpoint, String info2, String info3) {
202 if ((coolingSetpoint != this.coolingSetpoint) || (heatingSetpoint != this.heatingSetpoint)) {
203 this.currentCoolingSetpoint = coolingSetpoint
204 this.coolingSetpoint = coolingSetpoint
205 this.currentHeatingSetpoint = heatingSetpoint
206 this.heatingSetpoint = heatingSetpoint
207 this.latestCoolingSetPoint = coolingSetpoint
208 this.latestHeatingSetPoint = heatingSetpoint
209 thermostats[0].setHold(info1, coolingSetpoint, heatingSetpoint, info2, info3)
214 def setValue(LinkedHashMap eventDataMap) {
215 if (eventDataMap["name"] == "temperature") {
216 if (eventDataMap["value"].toInteger() != thermostats[0].temperature) {
217 this.temperature = eventDataMap["value"].toInteger()
218 this.currentTemperature = eventDataMap["value"].toInteger()
219 thermostats[0].setValue(eventDataMap["value"], "temperature")
220 sendEvent(eventDataMap)
222 } else if (eventDataMap["name"] == "heatingSetpoint") {
223 if (eventDataMap["value"].toInteger() != thermostats[0].heatingSetpoint) {
224 this.latestHeatingSetPoint = eventDataMap["value"].toInteger()
225 this.heatingSetpoint = eventDataMap["value"].toInteger()
226 thermostats[0].setValue(eventDataMap["value"], "heatingSetpoint")
227 sendEvent(eventDataMap)
229 } else if (eventDataMap["name"] == "coolingSetpoint") {
230 if (eventDataMap["value"].toInteger() != thermostats[0].coolingSetpoint) {
231 this.latestCoolingSetPoint = eventDataMap["value"].toInteger()
232 this.coolingSetpoint = eventDataMap["value"].toInteger()
233 thermostats[0].setValue(eventDataMap["value"], "coolingSetpoint")
234 sendEvent(eventDataMap)
236 } else if (eventDataMap["name"] == "thermostatSetpoint") {
237 if (eventDataMap["value"].toInteger() != thermostats[0].thermostatSetpoint) {
238 this.latestThermostatSetPoint = eventDataMap["value"].toInteger()
239 this.thermostatSetpoint = eventDataMap["value"].toInteger()
240 thermostats[0].setValue(eventDataMap["value"], "thermostatSetpoint")
241 sendEvent(eventDataMap)
243 } else if (eventDataMap["name"] == "thermostatMode") {
244 if (eventDataMap["value"] != thermostats[0].thermostatMode) {
245 this.thermostatLatestMode = eventDataMap["value"]
246 this.thermostatMode = eventDataMap["value"]
247 this.currentThermostatMode = eventDataMap["value"]
248 thermostats[0].setValue(eventDataMap["value"], "thermostatMode")
249 sendEvent(eventDataMap)
251 } else if (eventDataMap["name"] == "thermostatFanMode") {
252 if (eventDataMap["value"] != thermostats[0].thermostatFanMode) {
253 this.thermostatLatestFanMode = eventDataMap["value"]
254 this.thermostatFanMode = eventDataMap["value"]
255 thermostats[0].setValue(eventDataMap["value"], "thermostatFanMode")
256 sendEvent(eventDataMap)
258 } else if (eventDataMap["name"] == "thermostatOperatingState") {
259 if (eventDataMap["value"] != thermostats[0].thermostatOperatingState) {
260 this.thermostatLatestOperatingState = eventDataMap["value"]
261 this.thermostatOperatingState = eventDataMap["value"]
262 thermostats[0].setValue(eventDataMap["value"], "thermostatOperatingState")
263 sendEvent(eventDataMap)
268 def currentValue(String deviceFeature) {
269 thermostats[0].currentValue(deviceFeature)
272 def latestValue(String deviceFeature) {
273 thermostats[0].latestValue(deviceFeature)