import xbmc, xbmcaddon, xbmcgui
import resources.modules.scraper as scraper
from common import auth_check, get_device_info


username, password = auth_check()

devices = scraper.__get_json({"task": "devicelist", "username": username})
first = ""
second = ""
third = ""
k = 0

xbmc.log(' devices {}'.format(devices))
dev = []


for device in devices["boxes"]:
    if device["device_type"] == "box":
        ip, location, appversion, sessionid = get_device_info(device)
        if k == 0:
            dev.append(("{0}, {1}, {2}".format(ip, appversion, sessionid)))
            k = 1
        elif k == 1:
            dev.append(("{0}, {1}, {2}".format(ip, appversion, sessionid)))
            k = 2
        elif k == 2:
            dev.append(("{0}, {1}, {2}".format(ip, appversion, sessionid)))
            k = 3
        elif k == 3:
            dev.append(("{0}, {1}, {2}".format(ip, appversion, sessionid)))
            k = 4
        elif k == 4:
            dev.append(("{0}, {1}, {2}".format(ip, appversion, sessionid)))
            k = 5
        elif k == 5:
            dev.append(("{0}, {1}, {2}".format(ip, appversion, sessionid)))
            k = 6
        elif k == 6:
            dev.append(("{0}, {1}, {2}".format(ip, appversion, sessionid)))
            k = 7
        elif k == 7:
            dev.append(("{0}, {1}, {2}".format(ip, appversion, sessionid)))
            k = 8

if k == 0:
    xbmcgui.Dialog().ok("Active devices", ' No device active')
else:
    dev_rem = xbmcgui.Dialog().select("All Box Devices", dev)
