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