Commit #9: extension to the infrastructure with more devices + minor changes in extra...
[smartthings-infrastructure.git] / Thermostat / Thermostats.groovy
1 //Create a class for thermostat device
2 package Thermostat
3 import Timer.SimulatedTimer
4
5 public class Thermostats{
6         int deviceNumbers       
7         List thermostats        
8         def sendEvent   
9         def timers
10
11         //When we have only one device
12         private String id = "thermostatID0"
13         private String label = "thermostat0"
14         private String displayName = "thermostat0"
15         private int temperature = 66
16         private int currentCoolingSetpoint = 70
17         private int currentHeatingSetpoint = 50
18         private int coolingSetpoint = 70
19         private int thermostatSetpoint = 60
20         private int heatingSetpoint = 50
21         private coolingSetpointRange = [70, 90]
22         private thermostatSetpointRange = [50, 70]
23         private heatingSetpointRange = [20, 50]
24         private supportedThermostatFanModes = ["auto", "fanCirculate", "circulate", "fanOn", "on"]
25         private supportedThermostatModes = ["auto", "cool", "emergencyHeat", "heat", "off"]
26         private String thermostatOperatingState = "cooling"
27         private String thermostatFanMode = "auto"
28         private String thermostatMode = "auto"
29
30         Thermostats(Closure sendEvent, int deviceNumbers) {
31                 this.sendEvent = sendEvent
32                 this.timers = new SimulatedTimer()
33                 this.deviceNumbers = deviceNumbers
34                 this.thermostats = []
35
36                 thermostats.add(new Thermostat(sendEvent, id, label, displayName, this.temperature, this.currentCoolingSetpoint, 
37                                                this.currentHeatingSetpoint, this.coolingSetpoint, this.thermostatSetpoint, this.heatingSetpoint, this.coolingSetpointRange,
38                                                this.thermostatSetpointRange, this.heatingSetpointRange, this.supportedThermostatFanModes, this.supportedThermostatModes,
39                                                this.thermostatOperatingState, this.thermostatFanMode,  this.thermostatMode))
40         }
41
42         //Methods for closures
43         def count(Closure Input) {
44                 thermostats.count(Input)
45         }
46         def size() {
47                 thermostats.size()
48         }
49         def each(Closure Input) {
50                 thermostats.each(Input)
51         }
52         def find(Closure Input) {
53                 thermostats.find(Input)
54         }
55         def collect(Closure Input) {
56                 thermostats.collect(Input)
57         }
58
59         //By Apps
60         def setCoolingSetpoint(int coolingSetpoint) {
61                 thermostats[0].setCoolingSetpoint(coolingSetpoint)
62         }
63
64         def setHeatingSetpoint(int heatingSetpoint) {
65                 thermostats[0].setHeatingSetpoint(heatingSetpoint)
66         }
67
68         def setSchedule() {
69                 //Not implemented yet
70         }
71
72         def setThermostatFanMode(String thermostatFanMode) {
73                 thermostats[0].setThermostatFanMode(thermostatFanMode)
74         }
75
76         def setThermostatMode(String thermostatMode) {
77                 thermostats[0].setThermostatMode(thermostatMode)
78         }
79
80
81         def getAt(int ix) {
82                 locks[ix]
83         }
84 }
85