Commit #9: More classes + Extractor with Rahmadi's editions + Fixing some bugs
[smartthings-infrastructure.git] / Thermostat / Thermostat.groovy
1 //Create a class for thermostat device
2 package Thermostat
3 import Timer.SimulatedTimer
4
5 public class Thermostat {
6         private String id
7         private String label
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
25         def sendEvent
26         def timers
27
28
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,
32                    String climateName) {
33                 this.id = id
34                 this.label = label
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
52         }
53
54
55         //By Apps
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!")
60         }
61
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!")
66         }
67
68         def setSchedule() {
69                 //Not implemented yet
70         }
71
72         def setThermostatFanMode(String thermostatFanMode) {
73                 this.thermostatFanMode = thermostatFanMode
74                 println("Fan mode of the thermostat with id:$id is changed to $thermostatFanMode!")
75         }
76
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!")
81         }
82
83         def cool() {
84                 this.thermostatMode = "cool"
85                 this.currentThermostatMode = "cool"
86                 println("Mode of the thermostat with id:$id is changed to cool!")
87         }
88
89         def heat() {
90                 this.thermostatMode = "heat"
91                 this.currentThermostatMode = "heat"
92                 println("Mode of the thermostat with id:$id is changed to heat!")
93         }
94
95         def auto() {
96                 this.thermostatMode = "auto"
97                 this.currentThermostatMode = "auto"
98                 println("Mode of the thermostat with id:$id is changed to auto!")
99         }
100
101         def off() {
102                 this.thermostatMode = "off"
103                 this.currentThermostatMode = "off"
104                 println("Mode of the thermostat with id:$id is changed to off!")
105         }
106
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!")
110         }
111
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!")
119         }
120
121         //By Model Checker
122         def setValue(String value) {
123                 println("the thermostat with id:$id is $value!")
124                 this.thermostatMode = value
125                 this.currentThermostatMode = value
126         }
127
128 }