Removing getXXX methods + properties. Adding getProperty feature to SmartThing(s)
[smartthings-infrastructure.git] / Thermostat / Thermostat.groovy
index 720ba8270d078126988a82a9dfb37e5acdbe27be..21c897f9a6e608d8a0ba4e06b46f65aef33cf162 100644 (file)
 //Create a class for thermostat device
 package Thermostat
-import Timer.SimulatedTimer
-
-public class Thermostat {
-       private String id
-       private String label
-       private String displayName
-       private int temperature
-       private int currentCoolingSetpoint
-       private int currentHeatingSetpoint
-       private int coolingSetpoint
-       private int thermostatSetpoint
-       private int heatingSetpoint
-       private List coolingSetpointRange
-       private List thermostatSetpointRange
-       private List heatingSetpointRange
-       private List supportedThermostatFanModes
-       private List supportedThermostatModes
-       private String thermostatOperatingState
-       private String thermostatFanMode
-       private String thermostatMode
-       private String currentThermostatMode
-       private String climateName
-       def sendEvent
-       def timers
-
-
-       Thermostat(Closure sendEvent, String id, String label, String displayName, int temperature, int currentCoolingSetpoint, int currentHeatingSetpoint, int coolingSetpoint, 
-                   int thermostatSetpoint, int heatingSetpoint, List coolingSetpointRange, List thermostatSetpointRange, List heatingSetpointRange, 
-                   List supportedThermostatFanModes, List supportedThermostatModes, String thermostatOperatingState, String thermostatFanMode, String thermostatMode,
-                  String climateName) {
+import SmartThing.SmartThing
+
+class Thermostat extends SmartThing {
+       // id, label, and display name of the device
+       String id
+       String label
+       String displayName
+       // Maps from features to values
+       HashMap<String, String> deviceValuesMap = new HashMap<String, String>()
+       HashMap<String, Integer> deviceIntValuesMap = new HashMap<String, Integer>()
+
+       Thermostat(Closure sendEvent, String id, String label, String displayName, Integer currentTemperature, Integer currentCoolingSetpoint, 
+                   Integer currentHeatingSetpoint, Integer currentThermostatSetPoint, String currentThermostatOperatingState, String currentThermostatFanMode, 
+                  String currentThermostatMode, String currentClimateName) {
+               deviceValueSmartThing = deviceValuesMap
+               deviceIntValueSmartThing = deviceIntValuesMap
+               idSmartThing = id
+               labelSmartThing = label
+               displayNameSmartThing = displayName
+               sendEventSmartThings = sendEvent
+
+               // Initialization
                this.id = id
                this.label = label
-               this.sendEvent = sendEvent
-               this.temperature = temperature
-               this.currentCoolingSetpoint = currentCoolingSetpoint
-               this.currentHeatingSetpoint = currentHeatingSetpoint
-               this.coolingSetpoint = coolingSetpoint
-               this.thermostatSetpoint = thermostatSetpoint
-               this.heatingSetpoint = heatingSetpoint
-               this.coolingSetpointRange = coolingSetpointRange
-               this.thermostatSetpointRange = thermostatSetpointRange
-               this.heatingSetpointRange = heatingSetpointRange
-               this.supportedThermostatFanModes = supportedThermostatFanModes
-               this.supportedThermostatModes = supportedThermostatModes
-               this.thermostatOperatingState = thermostatOperatingState
-               this.thermostatFanMode = thermostatFanMode
-               this.thermostatMode = thermostatMode
-               this.currentThermostatMode = thermostatMode
-               this.climateName = climateName
+               this.displayName = displayName
+
+               deviceValuesMap.put("temperature", currentTemperature)
+               deviceValuesMap.put("thermostatOperatingState", currentThermostatOperatingState)
+               deviceValuesMap.put("thermostatFanMode", currentThermostatFanMode)
+               deviceValuesMap.put("thermostatMode", currentThermostatMode)
+               deviceValuesMap.put("climateName", currentClimateName)
+               deviceIntValuesMap.put("coolingSetpoint", currentCoolingSetpoint)
+               deviceIntValuesMap.put("heatingSetpoint", currentHeatingSetpoint)
+               deviceIntValuesMap.put("thermostatSetpoint", currentThermostatSetPoint)
        }
 
+       // Methods to set values
+       def setThermostatSetpoint(int newValue) {
+               action(newValue, "thermostatSetpoint")
+       }
+
+       def setCoolingSetpoint(int newValue) {
+               action(newValue, "coolingSetpoint")
+       }
+
+       def setCoolingSetpoint(String newValue) {
+               setCoolingSetpoint(newValue.toInteger())
+       }
 
-       //By Apps
-       def setCoolingSetpoint(int coolingSetpoint) {
-               this.coolingSetpoint = coolingSetpoint
-               this.currentCoolingSetpoint = currentCoolingSetpoint
-               println("Cooling set point for the thermostat with id:$id is changed to $coolingSetpoint!")
+       def setHeatingSetpoint(int newValue) {
+               action(newValue, "heatingSetpoint")
        }
 
-       def setHeatingSetpoint(int heatingSetpoint) {
-               this.heatingSetpoint = heatingSetpoint
-               this.currentHeatingSetpoint = currentHeatingSetpoint
-               println("Heating set point for the thermostat with id:$id is changed to $heatingSetpoint!")
+       def setHeatingSetpoint(String newValue) {
+               setHeatingSetpoint(newValue.toInteger())
        }
 
-       def setSchedule() {
-               //Not implemented yet
+       def setThermostatFanMode(String newValue) {
+               action(newValue, "thermostatFanMode")
        }
 
-       def setThermostatFanMode(String thermostatFanMode) {
-               this.thermostatFanMode = thermostatFanMode
-               println("Fan mode of the thermostat with id:$id is changed to $thermostatFanMode!")
+       def setThermostatOperatingState(String newValue) {
+               action(newValue, "thermostatOperatingState")
        }
 
-       def setThermostatMode(String thermostatMode) {
-               this.thermostatMode = thermostatMode
-               this.currentThermostatMode = currentThermostatMode
-               println("Mode of the thermostat with id:$id is changed to $thermostatMode!")
+       def setThermostatMode(String newValue) {
+               action(newValue, "thermostatMode")
        }
 
        def cool() {
-               this.thermostatMode = "cool"
-               this.currentThermostatMode = "cool"
-               println("Mode of the thermostat with id:$id is changed to cool!")
+               action("cool", "thermostatMode")
        }
 
        def heat() {
-               this.thermostatMode = "heat"
-               this.currentThermostatMode = "heat"
-               println("Mode of the thermostat with id:$id is changed to heat!")
+               action("heat", "thermostatMode")
        }
 
        def auto() {
-               this.thermostatMode = "auto"
-               this.currentThermostatMode = "auto"
-               println("Mode of the thermostat with id:$id is changed to auto!")
+               action("auto", "thermostatMode")
+       }
+       
+       def emergencyHeat() {
+               action("emergencyHeat", "thermostatMode")
        }
 
        def off() {
-               this.thermostatMode = "off"
-               this.currentThermostatMode = "off"
-               println("Mode of the thermostat with id:$id is changed to off!")
+               action("off", "thermostatMode")
        }
 
-       def setClimate(String info, String givenClimateName) {
-               this.climateName = givenClimateName
-               println("Climate name of the thermostat with id:$id is changed to $givenClimateName!")
+       def setClimate(String info, String newValue) {
+               action(newValue, "climateName")
        }
 
        def setHold(String info1, int coolingSetpoint, int heatingSetpoint, String info2, String info3) {
-               this.coolingSetpoint = coolingSetpoint
-               this.currentCoolingSetpoint = currentCoolingSetpoint
-               println("Cooling set point for the thermostat with id:$id is changed to $coolingSetpoint!")
-               this.heatingSetpoint = heatingSetpoint
-               this.currentHeatingSetpoint = currentHeatingSetpoint
-               println("Heating set point for the thermostat with id:$id is changed to $heatingSetpoint!")
-       }
-
-       //By Model Checker
-       def setValue(String value) {
-               println("the thermostat with id:$id is $value!")
-               this.thermostatMode = value
-               this.currentThermostatMode = value
+               setHeatingSetpoint(heatingSetpoint)
+               setCoolingSetpoint(coolingSetpoint)
        }
-
 }