Fixing bugs in infrastructure
[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                 String id = "thermostatID0"
14                 String label = "thermostat"
15                 String displayName = "thermostat"
16                 String climateName = "climateName"
17                 String thermostatOperatingState
18                 String thermostatFanMode
19                 String thermostatMode
20                 Integer temperature
21                 Integer coolingSetpoint
22                 Integer heatingSetpoint
23                 Integer thermostatSetpoint
24
25                 if (init) {
26                         temperature = 60
27                         coolingSetpoint = 70
28                         heatingSetpoint = 35
29                         thermostatSetpoint = 50
30                         thermostatOperatingState = "off"
31                         thermostatFanMode = "off"
32                         thermostatMode = "off"
33                 } else {
34                         temperature = 66
35                         coolingSetpoint = 80
36                         heatingSetpoint = 50
37                         thermostatSetpoint = 60
38                         thermostatOperatingState = "heating"
39                         thermostatFanMode = "circulate"
40                         thermostatMode = "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 setThermostatSetpoint(int thermostatSetpoint) {
50                 thermostats[0].setThermostatSetpoint(thermostatSetpoint)
51         }
52
53         def setCoolingSetpoint(int coolingSetpoint) {
54                 thermostats[0].setCoolingSetpoint(coolingSetpoint)
55         }
56
57         def setCoolingSetpoint(String coolingSetpoint) {
58                 setCoolingSetpoint(coolingSetpoint.toInteger())
59         }
60
61         def setHeatingSetpoint(int heatingSetpoint) {
62                 thermostats[0].setHeatingSetpoint(heatingSetpoint)
63         }
64
65         def setHeatingSetpoint(String heatingSetpoint) {
66                 setHeatingSetpoint(heatingSetpoint.toInteger())
67         }
68
69         def setThermostatFanMode(String thermostatFanMode) {
70                 thermostats[0].setThermostatFanMode(thermostatFanMode)
71         }
72
73         def setThermostatMode(String thermostatMode) {
74                 thermostats[0].setThermostatMode(thermostatMode)
75         }
76
77         def setThermostatOperatingState(String thermostatOperatingState) {
78                 thermostats[0].setThermostatOperatingState(thermostatOperatingState)
79         }
80
81         def setClimate(String info, String givenClimateName) {
82                 thermostats[0].setClimate(info, givenClimateName)
83         }
84
85         def setHold(String info1, int coolingSetpoint, int heatingSetpoint, String info2, String info3) {
86                 setCoolingSetpoint(coolingSetpoint)
87                 setHeatingSetpoint(heatingSetpoint)
88         }
89
90         def cool() {
91                 thermostats[0].cool()
92         }
93
94         def heat() {
95                 thermostats[0].heat()
96         }
97         
98         def auto() {
99                 thermostats[0].auto()
100         }
101
102         def emergencyHeat() {
103                 thermostats[0].emergencyHeat()
104         }
105
106         def off() {
107                 thermostats[0].off()
108         }
109 }