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