Commit #8: New version of extractor with running the preferences method make things...
[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 int id = 50
13         private String label = "thermostat"
14         private String displayName = "thermostat"
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                 for (int i = 0;i < deviceNumbers;i++) {
36                         thermostats.add(new Thermostat(sendEvent, i+50, label+i.toString(), displayName+i.toString(), 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
43         //Methods for closures
44         def count(Closure Input) {
45                 thermostats.count(Input)
46         }
47         def size() {
48                 thermostats.size()
49         }
50         def each(Closure Input) {
51                 thermostats.each(Input)
52         }
53
54         //By Apps
55         def setCoolingSetpoint(int coolingSetpoint) {
56                 thermostats*.setCoolingSetpoint(coolingSetpoint)
57         }
58
59         def setHeatingSetpoint(int heatingSetpoint) {
60                 thermostats*.setHeatingSetpoint(heatingSetpoint)
61         }
62
63         def setSchedule() {
64                 //Not implemented yet
65         }
66
67         def setThermostatFanMode(String thermostatFanMode) {
68                 thermostats*.setThermostatFanMode(thermostatFanMode)
69         }
70
71         def setThermostatMode(String thermostatMode) {
72                 thermostats*.setThermostatMode(thermostatMode)
73         }
74
75
76         //By Model Checker(There is no event based on thermostat?)
77         /*def setValue(LinkedHashMap eventDataMap) {
78                 thermostats[eventDataMap["deviceId"]].setValue(eventDataMap["value"])
79                 if (deviceNumbers == 1)
80                         this.lockState = locks[eventDataMap["deviceId"]].lockState
81                         this.currentLock = locks[eventDataMap["deviceId"]].lockState
82                         this.lockLatestValue = locks[eventDataMap["deviceId"]].lockLatestValue
83                 sendEvent(eventDataMap)
84         }*/
85
86         def getAt(int ix) {
87                 locks[ix]
88         }
89 }
90