Infrastructure that works for all the locks' group!
[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                 if (this.coolingSetpoint != coolingSetpoint) {
58                         this.coolingSetpoint = coolingSetpoint
59                         this.currentCoolingSetpoint = currentCoolingSetpoint
60                         println("Cooling set point for the thermostat with id:$id is changed to $coolingSetpoint!")
61                         sendEvent([name: "coolingSetpoint", value: "$coolingSetpoint", deviceId: this.id, descriptionText: "",
62                                    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
63                 }
64         }
65
66         def setHeatingSetpoint(int heatingSetpoint) {
67                 if (this.heatingSetpoint != heatingSetpoint) {
68                         this.heatingSetpoint = heatingSetpoint
69                         this.currentHeatingSetpoint = currentHeatingSetpoint
70                         println("Heating set point for the thermostat with id:$id is changed to $heatingSetpoint!")
71                         sendEvent([name: "heatingSetpoint", value: "$heatingSetpoint", deviceId: this.id, descriptionText: "",
72                                    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
73                 }
74         }
75
76         def setSchedule() {
77                 //Not implemented yet
78         }
79
80         def setThermostatFanMode(String thermostatFanMode) {
81                 if (this.thermostatFanMode != thermostatFanMode) {
82                         this.thermostatFanMode = thermostatFanMode
83                         println("Fan mode of the thermostat with id:$id is changed to $thermostatFanMode!")
84                         sendEvent([name: "thermostatFanMode", value: "$thermostatFanMode", deviceId: this.id, descriptionText: "",
85                                    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
86                 }
87         }
88
89         def setThermostatMode(String thermostatMode) {
90                 if (this.thermostatMode != thermostatMode) {
91                         this.thermostatMode = thermostatMode
92                         this.currentThermostatMode = currentThermostatMode
93                         println("Mode of the thermostat with id:$id is changed to $thermostatMode!")
94                         sendEvent([name: "thermostatMode", value: "$thermostatMode", deviceId: this.id, descriptionText: "",
95                                    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
96                 }
97         }
98
99         def cool() {
100                 if (this.thermostatMode != "cool") {
101                         this.thermostatMode = "cool"
102                         this.currentThermostatMode = "cool"
103                         println("Mode of the thermostat with id:$id is changed to cool!")
104                         sendEvent([name: "cool", value: "cool", deviceId: this.id, descriptionText: "",
105                                    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
106                 }
107         }
108
109         def heat() {
110                 if (this.thermostatMode != "heat") {
111                         this.thermostatMode = "heat"
112                         this.currentThermostatMode = "heat"
113                         println("Mode of the thermostat with id:$id is changed to heat!")
114                         sendEvent([name: "heat", value: "heat", deviceId: this.id, descriptionText: "",
115                                    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
116                 }
117         }
118
119         def auto() {
120                 if (this.thermostatMode != "auto") {
121                         this.thermostatMode = "auto"
122                         this.currentThermostatMode = "auto"
123                         println("Mode of the thermostat with id:$id is changed to auto!")
124                         sendEvent([name: "auto", value: "auto", deviceId: this.id, descriptionText: "",
125                                    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
126                 }
127         }
128
129         def off() {
130                 if (this.thermostatMode != "off") {
131                         this.thermostatMode = "off"
132                         this.currentThermostatMode = "off"
133                         println("Mode of the thermostat with id:$id is changed to off!")
134                         sendEvent([name: "off", value: "off", deviceId: this.id, descriptionText: "",
135                                    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
136                 }
137         }
138
139         def setClimate(String info, String givenClimateName) {
140                 if (this.climateName != givenClimateName) {
141                         this.climateName = givenClimateName
142                         println("Climate name of the thermostat with id:$id is changed to $givenClimateName!")
143                 }
144         }
145
146         def setHold(String info1, int coolingSetpoint, int heatingSetpoint, String info2, String info3) {
147                 if ((this.heatingSetpoint != heatingSetpoint) || (this.coolingSetpoint != coolingSetpoint)) {
148                         this.coolingSetpoint = coolingSetpoint
149                         this.currentCoolingSetpoint = currentCoolingSetpoint
150                         println("Cooling set point for the thermostat with id:$id is changed to $coolingSetpoint!")
151                         this.heatingSetpoint = heatingSetpoint
152                         this.currentHeatingSetpoint = currentHeatingSetpoint
153                         println("Heating set point for the thermostat with id:$id is changed to $heatingSetpoint!")
154                 }
155         }
156
157         //By Model Checker
158         def setValue(String value, String name) {
159                 if ((name == "temperature") && (value != this.temperature)) {
160                         println("the temperature is $value!")
161                         this.temperature = value.toInteger()
162                 } else if ((name == "heatingSetpoint") && (value != this.heatingSetpoint)) {
163                         println("the heating set point of the thermostat with id:$id is $value!")
164                         this.heatingSetpoint = value.toInteger()
165                 } else if ((name == "coolingSetpoint") && (value != this.coolingSetpoint)) {
166                         println("the cooling set point of the thermostat with id:$id is $value!")
167                         this.coolingSetpoint = value.toInteger()
168                 } else if ((name == "thermostatSetpoint") && (value != this.thermostatSetpoint)) {
169                         println("the set point of the thermostat with id:$id is $value!")
170                         this.thermostatSetpoint = value.toInteger()
171                 } else if ((name == "thermostatMode") && (value != this.thermostatMode)) {
172                         println("the mode of the thermostat with id:$id is $value!")
173                         this.thermostatMode = value
174                 } else if ((name == "thermostatFanMode") && (value != this.thermostatFanMode)) {
175                         println("the fan mode of the thermostat with id:$id is $value!")
176                         this.thermostatFanMode = value
177                 } else if ((name == "thermostatOperatingState") && (value != this.thermostatOperatingState)) {
178                         println("the operating state of the thermostat with id:$id is $value!")
179                         this.thermostatOperatingState = value
180                 }
181         }
182
183 }