def web_devices(room_id=False, device_id=False): # if (not room_id) or (not device_id): raise HTTPError(404) # # Get and check user user = _check_user(request.get_cookie('user')) if not user: redirect('/web/login') # room_num = get_cfg_room_index(room_id) device_num = get_cfg_device_index(room_id, device_id) # if room_id == -1 or device_id == -1: raise HTTPError(404) # timestamp = datetime.datetime.now() queue_item = {'timestamp': timestamp, 'response_queue': cfg.key_q_response_web_device, 'room_num': room_num, 'device_num': device_num, 'user': request.get_cookie('user')} # q_devices[room_num][device_num].put(queue_item) # time.sleep(0.1) # while datetime.datetime.now() < (timestamp + datetime.timedelta(seconds=cfg.request_timeout)): if not q_dict[cfg.key_q_response_web_device].empty(): return create_device(user, q_dict[cfg.key_q_response_web_device].get(), '{room_name}: {device_name}'.format(room_name=get_cfg_room_name(room_id), device_name=get_cfg_device_name(room_id, device_id)), '{room_name}: {device_name}'.format(room_name=get_cfg_room_name(room_id), device_name=get_cfg_device_name(room_id, device_id))) # raise HTTPError(500)
def send_command_device(room_id=False, device_id=False): # if (not room_id) or (not device_id): raise HTTPError(404) # timestamp = datetime.datetime.now() # room_num = get_cfg_room_index(room_id) device_num = get_cfg_device_index(room_id, device_id) # if room_id == -1 or device_id == -1: raise HTTPError(404) # cmd_dict = request.json # queue_item = {'timestamp': timestamp, 'response_queue': cfg.key_q_response_command, 'room_num': room_num, 'device_num': device_num, 'request': cmd_dict} # q_devices[room_num][device_num].put(queue_item) # time.sleep(0.1) # while datetime.datetime.now() < (timestamp + datetime.timedelta(seconds=cfg.request_timeout)): if not q_dict[cfg.key_q_response_command].empty(): # rsp = q_dict[cfg.key_q_response_command].get() # if isinstance(rsp, bool): return HTTPResponse(status=200) if rsp else HTTPResponse(status=400) else: return HTTPResponse(body=str(rsp), status=200) if bool(rsp) else HTTPResponse(status=400) # raise HTTPError(500)