def get_config(request): # args = get_request_log_args(request) # try: # data = { 'service_id': get_cfg_serviceid(), 'name_long': get_cfg_name_long(), 'name_short': get_cfg_name_short(), 'subservices': get_cfg_subservices(), 'groups': get_cfg_groups(), 'ui_links': [] } # status = httpStatusSuccess # args['result'] = logPass args['http_response_code'] = status args['description'] = '-' log_inbound(**args) # return HTTPResponse(body=data, status=status) # except Exception as e: # status = httpStatusServererror # args['result'] = logException args['http_response_code'] = status args['description'] = '-' args['exception'] = e log_inbound(**args) # raise HTTPError(status)
def get_ui_index(request): # args = get_request_log_args(request) # try: with open( os.path.join(os.path.dirname(__file__), '..', 'webfiles/index.html'), 'r') as f: page_body = f.read() # status = httpStatusSuccess args['result'] = logPass # args['http_response_code'] = status args['description'] = '-' log_inbound(**args) # response = HTTPResponse() response.status = status response.body = page_body enable_cors(response) # return response # except Exception as e: # status = httpStatusServererror # args['result'] = logException args['http_response_code'] = status args['description'] = '-' args['exception'] = e log_inbound(**args) # raise HTTPError(status)
def get_powerstatus(request, _xbox): # args = get_request_log_args(request) # try: # isOn = _xbox.power_status() # data = {'isOn': isOn} # status = httpStatusSuccess # args['result'] = logPass args['http_response_code'] = status args['description'] = '-' log_inbound(**args) # response = HTTPResponse() response.status = status response.body = data enable_cors(response) # return response # except Exception as e: status = httpStatusServererror # args['result'] = logException args['http_response_code'] = status args['description'] = '-' args['exception'] = e log_inbound(**args) # raise HTTPError(status)
def get_ui_module(request, service, filename): # args = get_request_log_args(request) # try: # status = httpStatusSuccess args['result'] = logPass # args['http_response_code'] = status args['description'] = '-' log_inbound(**args) # root = os.path.join( os.path.dirname(__file__), '..', 'webfiles/modules/{service}'.format(service=service)) # response = static_file(filename, root=root) response.status = status enable_cors(response) # return response # except Exception as e: # status = httpStatusServererror # args['result'] = logException args['http_response_code'] = status args['description'] = '-' args['exception'] = e log_inbound(**args) # raise HTTPResponse(status=status)
def post_enterpin(request, _virginmedia_tivo): # args = get_request_log_args(request) # try: # r = _virginmedia_tivo.sendPin() # if not bool(r): status = httpStatusFailure else: status = httpStatusSuccess # args['result'] = logPass args['http_response_code'] = status args['description'] = '-' log_inbound(**args) # response = HTTPResponse() response.status = status # return response # except Exception as e: status = httpStatusServererror # args['result'] = logException args['http_response_code'] = status args['description'] = '-' args['exception'] = e log_inbound(**args) # raise HTTPError(status)
def get_commands(request, _tvlgnetcast): # args = get_request_log_args(request) # try: # data = _tvlgnetcast.getCommands() # status = httpStatusSuccess # args['result'] = logPass args['http_response_code'] = status args['description'] = '-' log_inbound(**args) # return HTTPResponse(body=data, status=status) # except Exception as e: # status = httpStatusServererror # args['result'] = logException args['http_response_code'] = status args['description'] = '-' args['exception'] = e log_inbound(**args) # raise HTTPError(status)
def get_ui_favicon(request): # args = get_request_log_args(request) # try: # status = httpStatusSuccess args['result'] = logPass # args['http_response_code'] = status args['description'] = '-' log_inbound(**args) # root = os.path.join(os.path.dirname(__file__), '..', 'webfiles/images/logo') # response = static_file('favicon.ico', root=root) response.status = status enable_cors(response) # return response # except Exception as e: # status = httpStatusServererror # args['result'] = logException args['http_response_code'] = status args['description'] = '-' args['exception'] = e log_inbound(**args) # raise HTTPResponse(status=status)
def get_commands(request, _virginmedia_tivo): # args = get_request_log_args(request) # try: # data = _virginmedia_tivo.getCommands() # status = httpStatusSuccess # args['result'] = logPass args['http_response_code'] = status args['description'] = '-' log_inbound(**args) # response = HTTPResponse() response.status = status response.body = data # return response # except Exception as e: status = httpStatusServererror # args['result'] = logException args['http_response_code'] = status args['description'] = '-' args['exception'] = e log_inbound(**args) # raise HTTPError(status)
def get_sunrisesunset(request, _weather, _sunrisesunset, date): # # 'date' in YYYY-MM-DD format. Also accepts other date formats and even relative date formats. # If not present, date defaults to current date. Optional. # args = get_request_log_args(request) # try: # location = _weather.get_location() lat = location['latitude'] long = location['longitude'] # if date: data = _sunrisesunset.get_sunrise_sunset(lat, long, date) else: data = _sunrisesunset.get_sunrise_sunset(lat, long, 'today') # if not bool(data): status = httpStatusFailure args['result'] = logFail else: status = httpStatusSuccess args['result'] = logPass # args['http_response_code'] = status args['description'] = '-' log_inbound(**args) # response = HTTPResponse() response.status = status # if not isinstance(data, bool): response.body = data # return response # except Exception as e: # status = httpStatusServererror # args['result'] = logException args['http_response_code'] = status args['description'] = '-' args['exception'] = e log_inbound(**args) # raise HTTPError(status)
def get_all(request, _weather, _sunrisesunset): # args = get_request_log_args(request) # try: # data = _weather.get_weather_forecast() # if not bool(data): status = httpStatusFailure args['result'] = logFail else: status = httpStatusSuccess args['result'] = logPass # for day_key in data['days'].keys(): # data['days'][day_key][ 'sunRiseSet'] = _sunrisesunset.get_sunrise_sunset( data['location']['latitude'], data['location']['longitude'], data['days'][day_key]['date']) # # args['http_response_code'] = status args['description'] = '-' log_inbound(**args) # response = HTTPResponse() response.status = status # if not isinstance(data, bool): response.body = data # return response # except Exception as e: # status = httpStatusServererror # args['result'] = logException args['http_response_code'] = status args['description'] = '-' args['exception'] = e log_inbound(**args) # raise HTTPError(status)
def post_command_touchMove(request, _tvlgnetcast): # args = get_request_log_args(request) # try: # data_dict = request.json # if validate_touchMove(data_dict): # x = data_dict['touchMoveX'] y = data_dict['touchMoveY'] r = _tvlgnetcast.sendTouchmove(x, y) # if not bool(r): status = httpStatusFailure result = logFail else: status = httpStatusSuccess result = logPass else: status = httpStatusBadrequest result = logFail # args['result'] = result args['http_response_code'] = status args['description'] = '-' log_inbound(**args) # response = HTTPResponse() response.status = status enable_cors(response) # return response # except Exception as e: # status = httpStatusServererror # args['result'] = logException args['http_response_code'] = status args['description'] = '-' args['exception'] = e log_inbound(**args) # raise HTTPError(status)
def post_channel(request, _virginmedia_tivo): # args = get_request_log_args(request) # try: # data_dict = request.json # if validate_channel(data_dict): # channel = data_dict['channel'] if 'plus1' in data_dict: plus1 = data_dict['plus1'] else: plus1 = False # r = _virginmedia_tivo.sendChannel(channel, plus1) # if not bool(r): status = httpStatusFailure else: status = httpStatusSuccess else: status = httpStatusBadrequest # args['result'] = logPass args['http_response_code'] = status args['description'] = '-' log_inbound(**args) # response = HTTPResponse() response.status = status # return response # except Exception as e: status = httpStatusServererror # args['result'] = logException args['http_response_code'] = status args['description'] = '-' args['exception'] = e log_inbound(**args) # raise HTTPError(status)
def get_forecast(request, _weather, option): # args = get_request_log_args(request) # try: # if option == 'all': data = _weather.get_weather_forecast() elif option == '3hourly': data = False elif option == 'daily': data = False else: data = False # if not bool(data): status = httpStatusFailure args['result'] = logFail else: status = httpStatusSuccess args['result'] = logPass # args['http_response_code'] = status args['description'] = '-' log_inbound(**args) # response = HTTPResponse() response.status = status # if not isinstance(data, bool): response.body = data # return response # except Exception as e: # status = httpStatusServererror # args['result'] = logException args['http_response_code'] = status args['description'] = '-' args['exception'] = e log_inbound(**args) # raise HTTPError(status)
def get_apps_all(request, _tvlgnetcast): # args = get_request_log_args(request) # try: # r = _tvlgnetcast.getApps_all() # # Add URI for retrieving image item for k in r.keys(): r[k]['image'] = '/img/appicon/{auid}'.format(auid=r[k]['auid']) # if not bool(r): status = httpStatusFailure result = logFail else: status = httpStatusSuccess result = logPass # args['result'] = result args['http_response_code'] = status args['description'] = '-' log_inbound(**args) # response = HTTPResponse() response.status = status enable_cors(response) # if not isinstance(r, bool): response.body = r # return response # except Exception as e: # status = httpStatusServererror # args['result'] = logException args['http_response_code'] = status args['description'] = '-' args['exception'] = e log_inbound(**args) # raise HTTPError(status)
def get_volume(request, _tvlgnetcast): # args = get_request_log_args(request) # try: # r = _tvlgnetcast.getVolume() # if not bool(r): status = httpStatusFailure result = logFail else: status = httpStatusSuccess result = logPass # args['result'] = result args['http_response_code'] = status args['description'] = '-' log_inbound(**args) # response = HTTPResponse() response.status = status enable_cors(response) # if not isinstance(r, bool): response.body = r # return response # except Exception as e: # status = httpStatusServererror # args['result'] = logException args['http_response_code'] = status args['description'] = '-' args['exception'] = e log_inbound(**args) # raise HTTPError(status)
def post_ui_modules(request): # args = get_request_log_args(request) # try: # new_modules = request.json new_modules = new_modules['modules'] # r = set_cfg_details_modules(new_modules) if r: status = httpStatusSuccess args['result'] = logPass else: status = httpStatusFailure args['result'] = logFail # args['http_response_code'] = status args['description'] = '-' log_inbound(**args) # response = HTTPResponse() response.status = status enable_cors(response) # return response # except Exception as e: # status = httpStatusServererror # args['result'] = logException args['http_response_code'] = status args['description'] = '-' args['exception'] = e log_inbound(**args) # raise HTTPResponse(status=status)
def get_location(request, _weather): # args = get_request_log_args(request) # try: # data = _weather.get_location() # if not bool(data): status = httpStatusFailure args['result'] = logFail else: status = httpStatusSuccess args['result'] = logPass # args['http_response_code'] = status args['description'] = '-' log_inbound(**args) # response = HTTPResponse() response.status = status # if not isinstance(data, bool): response.body = data # return response # except Exception as e: # status = httpStatusServererror # args['result'] = logException args['http_response_code'] = status args['description'] = '-' args['exception'] = e log_inbound(**args) # raise HTTPError(status)
def post_device_specific(request, _nest, device_type, device_id): # args = get_request_log_args(request) # try: # command = request.json # if device_type == 'thermostat': if validate_thermostat(command): status = httpStatusSuccess if _nest.setThermostat(device_id, command) else httpStatusFailure else: status = httpStatusBadrequest else: status = httpStatusBadrequest # args['result'] = logPass if status == httpStatusSuccess else logFail # args['http_response_code'] = status args['description'] = '-' log_inbound(**args) # response = HTTPResponse() response.status = status # return response # except Exception as e: # status = httpStatusServererror # args['result'] = logException args['http_response_code'] = status args['description'] = '-' args['exception'] = e log_inbound(**args) # raise HTTPError(status)
def get_devices_type(request, _nest, device_type): # args = get_request_log_args(request) # try: # r = _nest.getDevicesType(device_type) # if not bool(r): status = httpStatusFailure args['result'] = logFail else: status = httpStatusSuccess args['result'] = logPass # args['http_response_code'] = status args['description'] = '-' log_inbound(**args) # response = HTTPResponse() response.status = status # if not isinstance(r, bool): response.body = r # return response # except Exception as e: # status = httpStatusServererror # args['result'] = logException args['http_response_code'] = status args['description'] = '-' args['exception'] = e log_inbound(**args) # raise HTTPError(status)
def post_command_touchClick(request, _tvlgnetcast): # args = get_request_log_args(request) # try: # r = _tvlgnetcast.sendTouchclick() # if not bool(r): status = httpStatusFailure result = logFail else: status = httpStatusSuccess result = logPass # args['result'] = result args['http_response_code'] = status args['description'] = '-' log_inbound(**args) # response = HTTPResponse() response.status = status enable_cors(response) # return response # except Exception as e: # status = httpStatusServererror # args['result'] = logException args['http_response_code'] = status args['description'] = '-' args['exception'] = e log_inbound(**args) # raise HTTPError(status)
def get_checkchannels(request): # args = get_request_log_args(request) # try: # r = checkChannels() # if not r: status = httpStatusFailure else: status = httpStatusSuccess # args['result'] = logPass args['http_response_code'] = status args['description'] = '-' log_inbound(**args) # response = HTTPResponse() response.status = status # if not isinstance(r, bool): response.body = r # return response # except Exception as e: status = httpStatusServererror # args['result'] = logException args['http_response_code'] = status args['description'] = '-' args['exception'] = e log_inbound(**args) # raise HTTPError(status)
def get_recordings(request, _virginmedia_tivo): # args = get_request_log_args(request) # try: # r = _virginmedia_tivo.getRecordings() # if not bool(r): status = httpStatusFailure else: status = httpStatusSuccess # args['result'] = logPass args['http_response_code'] = status args['description'] = '-' log_inbound(**args) # response = HTTPResponse() response.status = status # if not isinstance(r, bool): response.body = r # return response # except Exception as e: status = httpStatusServererror # args['result'] = logException args['http_response_code'] = status args['description'] = '-' args['exception'] = e log_inbound(**args) # raise HTTPError(status)
def get_ui_config(request): # args = get_request_log_args(request) # try: # status = httpStatusSuccess args['result'] = logPass # args['http_response_code'] = status args['description'] = '-' log_inbound(**args) # modules = get_cfg_details_modules() tempModules = {} for module in modules: if not module['group'] in tempModules: tempModules[module['group']] = {} tempModules[module['group']][module['index']] = module # r = 'window.onload=function() {' # for groupKey in tempModules: modules = tempModules[groupKey] # for moduleKey in sorted(modules.keys()): module = modules[moduleKey] # moduleType = module['module'] group = module['group'] index = module['index'] # try: r += "module_init('{module}', '{group}', {index}, '{url}');\n".format( module=moduleType, group=group, index=index, url=module['url']) except: r += "module_init('{module}', '{group}', {index});\n".format( module=moduleType, group=group, index=index) # r += '}' # response = HTTPResponse() response.body = r response.status = status enable_cors(response) # return response # except Exception as e: # status = httpStatusServererror # args['result'] = logException args['http_response_code'] = status args['description'] = '-' args['exception'] = e log_inbound(**args) # raise HTTPResponse(status=status)