X-Git-Url: http://plrg.eecs.uci.edu/git/?p=smartthings-infrastructure.git;a=blobdiff_plain;f=Thermostat%2FThermostats.groovy;h=b2d59811ad6ddd828a7461e8f34d5fe653c29c72;hp=78386ab904cc5e8cfabbfe5463a888d884846695;hb=2d26e7af07daad1394408bdcf76150b5aacf3a8a;hpb=2c464dd719752b34106af7eb1e7451e6e03072f6 diff --git a/Thermostat/Thermostats.groovy b/Thermostat/Thermostats.groovy index 78386ab..b2d5981 100644 --- a/Thermostat/Thermostats.groovy +++ b/Thermostat/Thermostats.groovy @@ -1,72 +1,69 @@ //Create a class for thermostat device package Thermostat -import Timer.SimulatedTimer - -public class Thermostats{ - int deviceNumbers - List thermostats - def sendEvent - def timers - - //When we have only one device - private String id = "thermostatID0" - private String label = "thermostat0" - private String displayName = "thermostat0" - private int temperature = 66 - private int currentCoolingSetpoint = 70 - private int currentHeatingSetpoint = 50 - private int coolingSetpoint = 70 - private int thermostatSetpoint = 60 - private int heatingSetpoint = 50 - private coolingSetpointRange = [70, 90] - private thermostatSetpointRange = [50, 70] - private heatingSetpointRange = [20, 50] - private supportedThermostatFanModes = ["auto", "fanCirculate", "circulate", "fanOn", "on"] - private supportedThermostatModes = ["auto", "cool", "emergencyHeat", "heat", "off"] - private String thermostatOperatingState = "cooling" - private String thermostatFanMode = "auto" - private String thermostatMode = "auto" - - Thermostats(Closure sendEvent, int deviceNumbers) { - this.sendEvent = sendEvent - this.timers = new SimulatedTimer() - this.deviceNumbers = deviceNumbers - this.thermostats = [] - - thermostats.add(new Thermostat(sendEvent, id, label, displayName, this.temperature, this.currentCoolingSetpoint, - this.currentHeatingSetpoint, this.coolingSetpoint, this.thermostatSetpoint, this.heatingSetpoint, this.coolingSetpointRange, - this.thermostatSetpointRange, this.heatingSetpointRange, this.supportedThermostatFanModes, this.supportedThermostatModes, - this.thermostatOperatingState, this.thermostatFanMode, this.thermostatMode)) - } - - //Methods for closures - def count(Closure Input) { - thermostats.count(Input) - } - def size() { - thermostats.size() - } - def each(Closure Input) { - thermostats.each(Input) - } - def find(Closure Input) { - thermostats.find(Input) - } - def collect(Closure Input) { - thermostats.collect(Input) - } - - //By Apps +import SmartThing.SmartThings + +class Thermostats extends SmartThings { + List thermostats = new ArrayList() + + Thermostats(Closure sendEvent, boolean init) { + // Only initialize one time since we only have one device for each capability + thermostats = smartThings + + // Initialization + String id = "thermostatID0" + String label = "thermostat" + String displayName = "thermostat" + String climateName "climateName" + String thermostatOperatingState + String thermostatFanMode + String thermostatMode + Integer temperature + Integer coolingSetpoint + Integer heatingSetpoint + Integer thermostatSetpoint + + if (init) { + temperature = 60 + coolingSetpoint = 70 + heatingSetpoint = 35 + thermostatSetpoint = 50 + thermostatOperatingState = "off" + thermostatFanMode = "off" + thermostatMode = "off" + } else { + temperature = 66 + coolingSetpoint = 80 + heatingSetpoint = 50 + thermostatSetpoint = 60 + thermostatOperatingState = "heating" + thermostatFanMode = "circulate" + thermostatMode = "auto" + } + + thermostats.add(new Thermostat(sendEvent, id, label, displayName, temperature, coolingSetpoint, + heatingSetpoint, thermostatSetpoint, thermostatOperatingState, + thermostatFanMode, thermostatMode, climateName)) + } + + // Methods to set values + def setThermostatSetpoint(int thermostatSetpoint) { + thermostats[0].setThermostatSetpoint(thermostatSetpoint) + } + def setCoolingSetpoint(int coolingSetpoint) { thermostats[0].setCoolingSetpoint(coolingSetpoint) } + def setCoolingSetpoint(String coolingSetpoint) { + setCoolingSetpoint(coolingSetpoint.toInteger()) + } + def setHeatingSetpoint(int heatingSetpoint) { thermostats[0].setHeatingSetpoint(heatingSetpoint) } - def setSchedule() { - //Not implemented yet + def setHeatingSetpoint(String heatingSetpoint) { + setHeatingSetpoint(heatingSetpoint.toInteger()) } def setThermostatFanMode(String thermostatFanMode) { @@ -77,9 +74,36 @@ public class Thermostats{ thermostats[0].setThermostatMode(thermostatMode) } + def setThermostatOperatingState(String thermostatOperatingState) { + thermostats[0].setThermostatOperatingState(thermostatOperatingState) + } + + def setClimate(String info, String givenClimateName) { + thermostats[0].setClimate(info, givenClimateName) + } - def getAt(int ix) { - locks[ix] + def setHold(String info1, int coolingSetpoint, int heatingSetpoint, String info2, String info3) { + setCoolingSetpoint(coolingSetpoint) + setHeatingSetpoint(heatingSetpoint) + } + + def cool() { + thermostats[0].cool() + } + + def heat() { + thermostats[0].heat() + } + + def auto() { + thermostats[0].auto() + } + + def emergencyHeat() { + thermostats[0].emergencyHeat() } -} + def off() { + thermostats[0].off() + } +}