package Thermostat
import SmartThing.SmartThing
-//Importing mutable integer class
-import MutableInteger.MutableInteger
-
class Thermostat extends SmartThing {
// id, label, and display name of the device
- StringBuilder id = new StringBuilder()
- StringBuilder label = new StringBuilder()
- StringBuilder displayName = new StringBuilder()
- // Features with numberical values
- MutableInteger currentTemperature = new MutableInteger()
- MutableInteger currentCoolingSetpoint = new MutableInteger()
- MutableInteger currentHeatingSetpoint = new MutableInteger()
- MutableInteger currentThermostatSetPoint = new MutableInteger()
- // Features with string values
- StringBuilder currentThermostatOperatingState = new StringBuilder()
- StringBuilder currentThermostatFanMode = new StringBuilder()
- StringBuilder currentThermostatMode = new StringBuilder()
- StringBuilder currentClimateName = new StringBuilder()
+ String id
+ String label
+ String displayName
// Maps from features to values
- HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
- HashMap<String, MutableInteger> deviceIntValuesMap = new HashMap<String, MutableInteger>()
-
- Thermostat(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, MutableInteger currentTemperature, MutableInteger currentCoolingSetpoint,
- MutableInteger currentHeatingSetpoint, MutableInteger currentThermostatSetPoint, StringBuilder currentThermostatOperatingState, StringBuilder currentThermostatFanMode,
- StringBuilder currentThermostatMode, StringBuilder currentClimateName) {
- deviceValuesMap = deviceValueSmartThing
- deviceIntValuesMap = deviceIntValueSmartThing
+ 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
this.id = id
this.label = label
this.displayName = displayName
- this.currentTemperature = currentTemperature
- this.currentCoolingSetpoint = currentCoolingSetpoint
- this.currentHeatingSetpoint = currentHeatingSetpoint
- this.currentThermostatSetPoint = currentThermostatSetPoint
- this.currentThermostatOperatingState = currentThermostatOperatingState
- this.currentThermostatFanMode = currentThermostatFanMode
- this.currentThermostatMode = currentThermostatMode
- this.currentClimateName = currentClimateName
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(this.currentCoolingSetpoint, newValue, "coolingSetpoint")
+ action(newValue, "coolingSetpoint")
}
def setCoolingSetpoint(String newValue) {
}
def setHeatingSetpoint(int newValue) {
- action(this.currentHeatingSetpoint, newValue, "heatingSetpoint")
+ action(newValue, "heatingSetpoint")
}
def setHeatingSetpoint(String newValue) {
}
def setThermostatFanMode(String newValue) {
- action(this.currentThermostatFanMode, newValue, "thermostatFanMode")
+ action(newValue, "thermostatFanMode")
+ }
+
+ def setThermostatOperatingState(String newValue) {
+ action(newValue, "thermostatOperatingState")
}
def setThermostatMode(String newValue) {
- action(this.currentThermostatMode, newValue, "thermostatMode")
+ action(newValue, "thermostatMode")
}
def cool() {
- action(this.currentThermostatMode, "cool", "thermostatMode")
+ action("cool", "thermostatMode")
}
def heat() {
- action(this.currentThermostatMode, "heat", "thermostatMode")
+ action("heat", "thermostatMode")
}
def auto() {
- action(this.currentThermostatMode, "auto", "thermostatMode")
+ action("auto", "thermostatMode")
}
def emergencyHeat() {
- action(this.currentThermostatMode, "emergencyHeat", "thermostatMode")
+ action("emergencyHeat", "thermostatMode")
}
def off() {
- action(this.currentThermostatMode, "off", "thermostatMode")
+ action("off", "thermostatMode")
}
def setClimate(String info, String newValue) {
- action(currentClimateName, newValue, "climateName")
+ action(newValue, "climateName")
}
def setHold(String info1, int coolingSetpoint, int heatingSetpoint, String info2, String info3) {
setHeatingSetpoint(heatingSetpoint)
setCoolingSetpoint(coolingSetpoint)
}
-
- def action(StringBuilder variable, String newValue, String feature) {
- if (!variable.toString().equals(newValue)) {
- String tmpID = id.toString()
- variable.replace(0, variable.length(), newValue)
- println("$feature of the thermostat with id:$tmpID is changed to $newValue!")
- sendEvent([name: feature, value: newValue, deviceId: tmpID, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
- }
-
- def action(MutableInteger variable, int newValue, String feature) {
- if (!variable.getValue().equals(newValue)) {
- String tmpID = id.toString()
- variable.setValue(newValue)
- println("$feature for the thermostat with id:$tmpID is changed to $newValue!")
- sendEvent([name: feature, value: newValue, deviceId: tmpID, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
- }
-
- // Methods to return values
- def getCurrentTemperature() {
- return currentTemperature.getValue()
- }
-
- def getCurrentCoolingSetpoint() {
- return currentCoolingSetpoint.getValue()
- }
-
- def getCurrentHeatingSetpoint() {
- return currentHeatingSetpoint.getValue()
- }
-
- def getCurrentThermostatSetPoint() {
- return currentThermostatSetPoint.getValue()
- }
-
- def getCurrentThermostatOperatingState() {
- return currentThermostatOperatingState.toString()
- }
-
- def getCurrentThermostatFanMode() {
- return currentThermostatFanMode.toString()
- }
-
- def getCurrentThermostatMode() {
- return currentThermostatMode.toString()
- }
-
- def getCurrentClimateName() {
- return currentClimateName.toString()
- }
}