def setThermostatFanMode(iden): new_mode = request.query.mode try: if new_mode == "auto" or new_mode == "off": homeThermostats[iden].fanMode = new_mode else: return ThermostatError( 400, "Fan mode \"{}\" is invalid.".format(new_mode)).toJSON() return homeThermostats[iden].toJSON() except KeyError: return ThermostatError( 404, "Thermostat with id \"{}\" is not found in this home.".format( iden)).toJSON()
def setThermostatHeatPoint(iden): new_point = float(request.query.heatPoint) try: if new_point < 100 and new_point > 30: homeThermostats[iden].heatSetPoint = new_point else: return ThermostatError( 400, "Heat point: {} is invalid.".format(new_point)).toJSON() return homeThermostats[iden].toJSON() except KeyError: return ThermostatError( 404, "Thermostat with id: {} is not found in this home.".format( iden)).toJSON()
def setThermostatOperationMode(iden): new_mode = request.query.mode try: if new_mode == "cool" or new_mode == "heat" or new_mode == "off": homeThermostats[iden].operationMode = new_mode else: return ThermostatError( 400, "Operation mode: {} is invalid.".format(new_mode)).toJSON() return homeThermostats[iden].toJSON() except KeyError: return ThermostatError( 404, "Thermostat with id: {} is not found in this home.".format( iden)).toJSON()
def getThermostatName(iden): try: return homeThermostats[iden].name except KeyError: return ThermostatError( 404, "Thermostat with id: {} is not found in this home.".format( iden)).toJSON()
def getThermostatHeatPoint(iden): try: return str(homeThermostats[iden].heatSetPoint) except KeyError: return ThermostatError( 404, "Thermostat with id: {} is not found in this home.".format( iden)).toJSON()
def getThermostatCurrentTemp(iden): try: print(homeThermostats[iden].currentTemp) return str(homeThermostats[iden].currentTemp) except KeyError: return ThermostatError( 404, "Thermostat with id: {} is not found in this home.".format( iden)).toJSON()
def setThermostatName(iden): new_name = request.query.name try: homeThermostats[iden].name = new_name return homeThermostats[iden].toJSON() except KeyError: return ThermostatError( 404, "Thermostat with id: {} is not found in this home.".format( iden)).toJSON()
def error500(error): return ThermostatError(500, error.body).toJSON()
def error404(error): return ThermostatError(404, error.body).toJSON()