//Create a class for thermostat device package Thermostat 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 deviceValuesMap = new HashMap() HashMap deviceIntValuesMap = new HashMap() 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.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()) } def setHeatingSetpoint(int newValue) { action(newValue, "heatingSetpoint") } def setHeatingSetpoint(String newValue) { setHeatingSetpoint(newValue.toInteger()) } def setThermostatFanMode(String newValue) { action(newValue, "thermostatFanMode") } def setThermostatOperatingState(String newValue) { action(newValue, "thermostatOperatingState") } def setThermostatMode(String newValue) { action(newValue, "thermostatMode") } def cool() { action("cool", "thermostatMode") } def heat() { action("heat", "thermostatMode") } def auto() { action("auto", "thermostatMode") } def emergencyHeat() { action("emergencyHeat", "thermostatMode") } def off() { action("off", "thermostatMode") } def setClimate(String info, String newValue) { action(newValue, "climateName") } def setHold(String info1, int coolingSetpoint, int heatingSetpoint, String info2, String info3) { setHeatingSetpoint(heatingSetpoint) setCoolingSetpoint(coolingSetpoint) } }