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 currentCoolingSetpoint = 70
17 private int currentHeatingSetpoint = 50
18 private int coolingSetpoint = 70
19 private int thermostatSetpoint = 60
20 private int heatingSetpoint = 50
21 private coolingSetpointRange = [70, 90]
22 private thermostatSetpointRange = [50, 70]
23 private heatingSetpointRange = [20, 50]
24 private supportedThermostatFanModes = ["auto", "fanCirculate", "circulate", "fanOn", "on"]
25 private supportedThermostatModes = ["auto", "cool", "emergencyHeat", "heat", "off"]
26 private String thermostatOperatingState = "cooling"
27 private String thermostatFanMode = "auto"
28 private String thermostatMode = "auto"
29 private String currentThermostatMode = "auto"
30 private String climateName = ""
32 Thermostats(Closure sendEvent, int deviceNumbers) {
33 this.sendEvent = sendEvent
34 this.timers = new SimulatedTimer()
35 this.deviceNumbers = deviceNumbers
38 thermostats.add(new Thermostat(sendEvent, id, label, displayName, this.temperature, this.currentCoolingSetpoint,
39 this.currentHeatingSetpoint, this.coolingSetpoint, this.thermostatSetpoint, this.heatingSetpoint, this.coolingSetpointRange,
40 this.thermostatSetpointRange, this.heatingSetpointRange, this.supportedThermostatFanModes, this.supportedThermostatModes,
41 this.thermostatOperatingState, this.thermostatFanMode, this.thermostatMode, this.climateName))
44 //Methods for closures
45 def count(Closure Input) {
46 thermostats.count(Input)
51 def each(Closure Input) {
52 thermostats.each(Input)
54 def find(Closure Input) {
55 thermostats.find(Input)
57 def collect(Closure Input) {
58 thermostats.collect(Input)
62 def setCoolingSetpoint(int coolingSetpoint) {
63 thermostats[0].setCoolingSetpoint(coolingSetpoint)
64 this.currentCoolingSetpoint = coolingSetpoint
65 this.coolingSetpoint = coolingSetpoint
68 def setHeatingSetpoint(int heatingSetpoint) {
69 thermostats[0].setHeatingSetpoint(heatingSetpoint)
70 this.currentHeatingSetpoint = heatingSetpoint
71 this.heatingSetpoint = heatingSetpoint
78 def setThermostatFanMode(String thermostatFanMode) {
79 thermostats[0].setThermostatFanMode(thermostatFanMode)
80 this.thermostatFanMode = thermostatFanMode
83 def setThermostatMode(String thermostatMode) {
84 thermostats[0].setThermostatMode(thermostatMode)
85 this.thermostatMode = thermostatMode
86 this.currentThermostatMode = currentThermostatMode
91 this.thermostatMode = "cool"
92 this.currentThermostatMode = "cool"
97 this.thermostatMode = "heat"
98 this.currentThermostatMode = "heat"
102 thermostats[0].auto()
103 this.thermostatMode = "auto"
104 this.currentThermostatMode = "auto"
109 this.thermostatMode = "off"
110 this.currentThermostatMode = "off"
113 def setClimate(String info, String givenClimateName) {
114 thermostats[0].setClimate(info, givenClimateName)
115 this.climateName = givenClimateName
118 def setHold(String info1, int coolingSetpoint, int heatingSetpoint, String info2, String info3) {
119 thermostats[0].setHold(info1, coolingSetpoint, heatingSetpoint, info2, info3)
120 this.currentCoolingSetpoint = coolingSetpoint
121 this.coolingSetpoint = coolingSetpoint
122 this.currentHeatingSetpoint = heatingSetpoint
123 this.heatingSetpoint = heatingSetpoint
127 def setValue(LinkedHashMap eventDataMap) {
128 if (eventDataMap["name"] == "temperature") {
129 if (eventDataMap["value"] != thermostats[0].temperature) {
130 thermostats[0].setValue(eventDataMap["value"], "temperature")
131 this.temperature = thermostats[0].temperature
132 sendEvent(eventDataMap)
134 } else if (eventDataMap["name"] == "heatingSetpoint") {
135 if (eventDataMap["value"] != thermostats[0].heatingSetpoint) {
136 thermostats[0].setValue(eventDataMap["value"], "heatingSetpoint")
137 this.heatingSetpoint = thermostats[0].heatingSetpoint
138 sendEvent(eventDataMap)
140 } else if (eventDataMap["name"] == "coolingSetpoint") {
141 if (eventDataMap["value"] != thermostats[0].coolingSetpoint) {
142 thermostats[0].setValue(eventDataMap["value"], "coolingSetpoint")
143 this.coolingSetpoint = thermostats[0].coolingSetpoint
144 sendEvent(eventDataMap)
146 } else if (eventDataMap["name"] == "thermostatSetpoint") {
147 if (eventDataMap["value"] != thermostats[0].thermostatSetpoint) {
148 thermostats[0].setValue(eventDataMap["value"], "thermostatSetpoint")
149 this.thermostatSetpoint = thermostats[0].thermostatSetpoint
150 sendEvent(eventDataMap)
152 } else if (eventDataMap["name"] == "thermostatMode") {
153 if (eventDataMap["value"] != thermostats[0].thermostatMode) {
154 thermostats[0].setValue(eventDataMap["value"], "thermostatMode")
155 this.thermostatMode = thermostats[0].thermostatMode
156 this.currentThermostatMode = thermostats[0].currentThermostatMode
157 sendEvent(eventDataMap)
159 } else if (eventDataMap["name"] == "thermostatFanMode") {
160 if (eventDataMap["value"] != thermostats[0].thermostatFanMode) {
161 thermostats[0].setValue(eventDataMap["value"], "thermostatFanMode")
162 this.thermostatFanMode = thermostats[0].thermostatFanMode
163 sendEvent(eventDataMap)
165 } else if (eventDataMap["name"] == "thermostatOperatingState") {
166 if (eventDataMap["value"] != thermostats[0].thermostatOperatingState) {
167 thermostats[0].setValue(eventDataMap["value"], "thermostatOperatingState")
168 this.thermostatOperatingState = thermostats[0].thermostatOperatingState
169 sendEvent(eventDataMap)