693ba939f6c2096bf165af1e4981ef042e1c41eb
[smartthings-infrastructure.git] / Thermostat / Thermostats.groovy
1 //Create a class for thermostat device
2 package Thermostat
3 import SmartThing.SmartThings
4
5 //Importing mutable integer class
6 import MutableInteger.MutableInteger
7
8 class Thermostats extends SmartThings {
9         List thermostats = new ArrayList()
10
11         Thermostats(Closure sendEvent, boolean init) {
12                 // Only initialize one time since we only have one device for each capability
13                 thermostats = smartThings
14
15                 // Initialization
16                 StringBuilder id = new StringBuilder("thermostatID0")
17                 StringBuilder label = new StringBuilder("thermostat")
18                 StringBuilder displayName = new StringBuilder("thermostat0")
19                 StringBuilder climateName = new StringBuilder("climateName")
20                 StringBuilder thermostatOperatingState = new StringBuilder()
21                 StringBuilder thermostatFanMode = new StringBuilder()
22                 StringBuilder thermostatMode = new StringBuilder()
23                 MutableInteger temperature = new MutableInteger()
24                 MutableInteger coolingSetpoint = new MutableInteger()
25                 MutableInteger heatingSetpoint = new MutableInteger()
26                 MutableInteger thermostatSetpoint = new MutableInteger()
27
28                 if (init) {
29                         temperature.setValue(60)
30                         coolingSetpoint.setValue(70)
31                         heatingSetpoint.setValue(35)
32                         thermostatSetpoint.setValue(50)
33                         thermostatOperatingState.append("off")
34                         thermostatFanMode.append("off")
35                         thermostatMode.append("off")
36                 } else {
37                         temperature.setValue(66)
38                         coolingSetpoint.setValue(80)
39                         heatingSetpoint.setValue(50)
40                         thermostatSetpoint.setValue(60)
41                         thermostatOperatingState.append("heating")
42                         thermostatFanMode.append("circulate")
43                         thermostatMode.append("auto")
44                 }
45
46                 thermostats.add(new Thermostat(sendEvent, id, label, displayName, temperature, coolingSetpoint, 
47                                                heatingSetpoint, thermostatSetpoint, thermostatOperatingState, 
48                                                thermostatFanMode,  thermostatMode, climateName))
49         }
50
51         // Methods to set values
52         def setCoolingSetpoint(int coolingSetpoint) {
53                 thermostats[0].setCoolingSetpoint(coolingSetpoint)
54         }
55
56         def setCoolingSetpoint(String coolingSetpoint) {
57                 setCoolingSetpoint(coolingSetpoint.toInteger())
58         }
59
60         def setHeatingSetpoint(int heatingSetpoint) {
61                 thermostats[0].setHeatingSetpoint(heatingSetpoint)
62         }
63
64         def setHeatingSetpoint(String heatingSetpoint) {
65                 setHeatingSetpoint(heatingSetpoint.toInteger())
66         }
67
68         def setThermostatFanMode(String thermostatFanMode) {
69                 thermostats[0].setThermostatFanMode(thermostatFanMode)
70         }
71
72         def setThermostatMode(String thermostatMode) {
73                 thermostats[0].setThermostatMode(thermostatMode)
74         }
75
76         def setClimate(String info, String givenClimateName) {
77                 thermostats[0].setClimate(info, givenClimateName)
78         }
79
80         def setHold(String info1, int coolingSetpoint, int heatingSetpoint, String info2, String info3) {
81                 setCoolingSetpoint(coolingSetpoint)
82                 setHeatingSetpoint(heatingSetpoint)
83         }
84
85         def cool() {
86                 thermostats[0].cool()
87         }
88
89         def heat() {
90                 thermostats[0].heat()
91         }
92         
93         def auto() {
94                 thermostats[0].auto()
95         }
96
97         def emergencyHeat() {
98                 thermostats[0].emergencyHeat()
99         }
100
101         def off() {
102                 thermostats[0].off()
103         }
104
105         // Methods to return values
106         def getCurrentTemperature() {
107                 List tmpValues = new ArrayList()
108                 tmpValues.add(thermostats[0].getCurrentTemperature())
109                 return tmpValues
110         }
111
112         def getCurrentCoolingSetpoint() {
113                 List tmpValues = new ArrayList()
114                 tmpValues.add(thermostats[0].getCurrentCoolingSetpoint())
115                 return tmpValues
116         }
117         
118         def getCurrentHeatingSetpoint() {
119                 List tmpValues = new ArrayList()
120                 tmpValues.add(thermostats[0].getCurrentHeatingSetpoint())
121                 return tmpValues
122         }
123
124         def getCurrentThermostatSetPoint() {
125                 List tmpValues = new ArrayList()
126                 tmpValues.add(thermostats[0].getCurrentThermostatSetPoint())
127                 return tmpValues
128         }
129
130         def getCurrentThermostatOperatingState() {
131                 List tmpValues = new ArrayList()
132                 tmpValues.add(thermostats[0].getCurrentThermostatOperatingState())
133                 return tmpValues
134         }
135
136         def getCurrentThermostatFanMode() {
137                 List tmpValues = new ArrayList()
138                 tmpValues.add(thermostats[0].getCurrentThermostatFanMode())
139                 return tmpValues
140         }
141
142         def getCurrentThermostatMode() {
143                 List tmpValues = new ArrayList()
144                 tmpValues.add(thermostats[0].getCurrentThermostatMode())
145                 return tmpValues
146         }
147
148         def getCurrentClimateName() {
149                 List tmpValues = new ArrayList()
150                 tmpValues.add(thermostats[0].getCurrentClimateName())
151                 return tmpValues
152         }
153 }