Removing getXXX methods + properties. Adding getProperty feature to SmartThing(s)
[smartthings-infrastructure.git] / Thermostat / Thermostat.groovy
1 //Create a class for thermostat device
2 package Thermostat
3 import SmartThing.SmartThing
4
5 class Thermostat extends SmartThing {
6         // id, label, and display name of the device
7         String id
8         String label
9         String displayName
10         // Maps from features to values
11         HashMap<String, String> deviceValuesMap = new HashMap<String, String>()
12         HashMap<String, Integer> deviceIntValuesMap = new HashMap<String, Integer>()
13
14         Thermostat(Closure sendEvent, String id, String label, String displayName, Integer currentTemperature, Integer currentCoolingSetpoint, 
15                    Integer currentHeatingSetpoint, Integer currentThermostatSetPoint, String currentThermostatOperatingState, String currentThermostatFanMode, 
16                    String currentThermostatMode, String currentClimateName) {
17                 deviceValueSmartThing = deviceValuesMap
18                 deviceIntValueSmartThing = deviceIntValuesMap
19                 idSmartThing = id
20                 labelSmartThing = label
21                 displayNameSmartThing = displayName
22                 sendEventSmartThings = sendEvent
23
24                 // Initialization
25                 this.id = id
26                 this.label = label
27                 this.displayName = displayName
28
29                 deviceValuesMap.put("temperature", currentTemperature)
30                 deviceValuesMap.put("thermostatOperatingState", currentThermostatOperatingState)
31                 deviceValuesMap.put("thermostatFanMode", currentThermostatFanMode)
32                 deviceValuesMap.put("thermostatMode", currentThermostatMode)
33                 deviceValuesMap.put("climateName", currentClimateName)
34                 deviceIntValuesMap.put("coolingSetpoint", currentCoolingSetpoint)
35                 deviceIntValuesMap.put("heatingSetpoint", currentHeatingSetpoint)
36                 deviceIntValuesMap.put("thermostatSetpoint", currentThermostatSetPoint)
37         }
38
39         // Methods to set values
40         def setThermostatSetpoint(int newValue) {
41                 action(newValue, "thermostatSetpoint")
42         }
43
44         def setCoolingSetpoint(int newValue) {
45                 action(newValue, "coolingSetpoint")
46         }
47
48         def setCoolingSetpoint(String newValue) {
49                 setCoolingSetpoint(newValue.toInteger())
50         }
51
52         def setHeatingSetpoint(int newValue) {
53                 action(newValue, "heatingSetpoint")
54         }
55
56         def setHeatingSetpoint(String newValue) {
57                 setHeatingSetpoint(newValue.toInteger())
58         }
59
60         def setThermostatFanMode(String newValue) {
61                 action(newValue, "thermostatFanMode")
62         }
63
64         def setThermostatOperatingState(String newValue) {
65                 action(newValue, "thermostatOperatingState")
66         }
67
68         def setThermostatMode(String newValue) {
69                 action(newValue, "thermostatMode")
70         }
71
72         def cool() {
73                 action("cool", "thermostatMode")
74         }
75
76         def heat() {
77                 action("heat", "thermostatMode")
78         }
79
80         def auto() {
81                 action("auto", "thermostatMode")
82         }
83         
84         def emergencyHeat() {
85                 action("emergencyHeat", "thermostatMode")
86         }
87
88         def off() {
89                 action("off", "thermostatMode")
90         }
91
92         def setClimate(String info, String newValue) {
93                 action(newValue, "climateName")
94         }
95
96         def setHold(String info1, int coolingSetpoint, int heatingSetpoint, String info2, String info3) {
97                 setHeatingSetpoint(heatingSetpoint)
98                 setCoolingSetpoint(coolingSetpoint)
99         }
100 }