Пример #1
0
def html_menu_lhs():
    #
    html = ''
    #
    t = 0
    #
    a_list = get_cfg_idlist_accounts()
    a_num = 0
    #
    while a_num < len(a_list):
        #
        html += '<span class="sidebar_divider box-shadow"></span>'
        #
        label = get_cfg_account_name(a_list[a_num])
        img = get_device_logo(get_cfg_account_type(a_list[a_num]))
        #
        html += urlopen('web/html/html_menu/menu_sidebar_item.html').read().encode('utf-8').format(href=('/web/account/{account_id}').format(account_id=a_list[a_num]),
                                                                                              id='{account_id}'.format(account_id=a_list[a_num]),
                                                                                              cls='',
                                                                                              name=label,
                                                                                              img=img)

        #
        t += 1
        a_num += 1
    #
    r_list = get_cfg_idlist_rooms()
    r_num = 0
    #
    while r_num < len(r_list):
        d_list = get_cfg_idlist_devices(r_list[r_num])
        d_num = 0
        #
        html += '<span class="sidebar_divider box-shadow"></span>'
        #
        html += urlopen('web/html/html_menu/menu_sidebar_title.html').read().encode('utf-8').\
            format(name=get_cfg_room_name(r_list[r_num]))
        #
        while d_num < len(d_list):
            #
            label = get_cfg_device_name(r_list[r_num], d_list[d_num])
            img = get_device_logo(get_cfg_device_type(r_list[r_num], d_list[d_num]))
            #
            html += urlopen('web/html/html_menu/menu_sidebar_item.html').read().encode('utf-8').format(href=('/web/device/{room_id}/{device_id}').format(room_id=r_list[r_num],
                                                                                                                                                    device_id=d_list[d_num]),
                                                                                                  id='{room_id}_{device_id}'.format(room_id=r_list[r_num],
                                                                                                                                    device_id=d_list[d_num]),
                                                                                                  cls='',
                                                                                                  name=label,
                                                                                                  img=img)
            d_num += 1
        #
        r_num += 1
    #
    return urlopen('web/html/html_menu/menu_lhs.html').read().encode('utf-8').format(menu=html)
Пример #2
0
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)