1 //Create a class for thermostat device
3 import Timer.SimulatedTimer
5 public class Thermostat {
8 private String displayName
9 private int temperature
10 private int currentCoolingSetpoint
11 private int currentHeatingSetpoint
12 private int coolingSetpoint
13 private int thermostatSetpoint
14 private int heatingSetpoint
15 private List coolingSetpointRange
16 private List thermostatSetpointRange
17 private List heatingSetpointRange
18 private List supportedThermostatFanModes
19 private List supportedThermostatModes
20 private String thermostatOperatingState
21 private String thermostatFanMode
22 private String thermostatMode
23 private String currentThermostatMode
24 private String climateName
29 Thermostat(Closure sendEvent, String id, String label, String displayName, int temperature, int currentCoolingSetpoint, int currentHeatingSetpoint, int coolingSetpoint,
30 int thermostatSetpoint, int heatingSetpoint, List coolingSetpointRange, List thermostatSetpointRange, List heatingSetpointRange,
31 List supportedThermostatFanModes, List supportedThermostatModes, String thermostatOperatingState, String thermostatFanMode, String thermostatMode,
35 this.sendEvent = sendEvent
36 this.temperature = temperature
37 this.currentCoolingSetpoint = currentCoolingSetpoint
38 this.currentHeatingSetpoint = currentHeatingSetpoint
39 this.coolingSetpoint = coolingSetpoint
40 this.thermostatSetpoint = thermostatSetpoint
41 this.heatingSetpoint = heatingSetpoint
42 this.coolingSetpointRange = coolingSetpointRange
43 this.thermostatSetpointRange = thermostatSetpointRange
44 this.heatingSetpointRange = heatingSetpointRange
45 this.supportedThermostatFanModes = supportedThermostatFanModes
46 this.supportedThermostatModes = supportedThermostatModes
47 this.thermostatOperatingState = thermostatOperatingState
48 this.thermostatFanMode = thermostatFanMode
49 this.thermostatMode = thermostatMode
50 this.currentThermostatMode = thermostatMode
51 this.climateName = climateName
56 def setCoolingSetpoint(int coolingSetpoint) {
57 this.coolingSetpoint = coolingSetpoint
58 this.currentCoolingSetpoint = currentCoolingSetpoint
59 println("Cooling set point for the thermostat with id:$id is changed to $coolingSetpoint!")
62 def setHeatingSetpoint(int heatingSetpoint) {
63 this.heatingSetpoint = heatingSetpoint
64 this.currentHeatingSetpoint = currentHeatingSetpoint
65 println("Heating set point for the thermostat with id:$id is changed to $heatingSetpoint!")
72 def setThermostatFanMode(String thermostatFanMode) {
73 this.thermostatFanMode = thermostatFanMode
74 println("Fan mode of the thermostat with id:$id is changed to $thermostatFanMode!")
77 def setThermostatMode(String thermostatMode) {
78 this.thermostatMode = thermostatMode
79 this.currentThermostatMode = currentThermostatMode
80 println("Mode of the thermostat with id:$id is changed to $thermostatMode!")
84 this.thermostatMode = "cool"
85 this.currentThermostatMode = "cool"
86 println("Mode of the thermostat with id:$id is changed to cool!")
90 this.thermostatMode = "heat"
91 this.currentThermostatMode = "heat"
92 println("Mode of the thermostat with id:$id is changed to heat!")
96 this.thermostatMode = "auto"
97 this.currentThermostatMode = "auto"
98 println("Mode of the thermostat with id:$id is changed to auto!")
102 this.thermostatMode = "off"
103 this.currentThermostatMode = "off"
104 println("Mode of the thermostat with id:$id is changed to off!")
107 def setClimate(String info, String givenClimateName) {
108 this.climateName = givenClimateName
109 println("Climate name of the thermostat with id:$id is changed to $givenClimateName!")
112 def setHold(String info1, int coolingSetpoint, int heatingSetpoint, String info2, String info3) {
113 this.coolingSetpoint = coolingSetpoint
114 this.currentCoolingSetpoint = currentCoolingSetpoint
115 println("Cooling set point for the thermostat with id:$id is changed to $coolingSetpoint!")
116 this.heatingSetpoint = heatingSetpoint
117 this.currentHeatingSetpoint = currentHeatingSetpoint
118 println("Heating set point for the thermostat with id:$id is changed to $heatingSetpoint!")
122 def setValue(String value) {
123 println("the thermostat with id:$id is $value!")
124 this.thermostatMode = value
125 this.currentThermostatMode = value