def list_collector(query="",kind="scenes"):
    global TYPES, COMMANDS, VERBS
    #print("list_collector: query is {query}").format(query=query)

    feedback_list = []
    feedback = Feedback()

    if not kind in TYPES:
        return feedback

    args = string.split(query, " ")    
    executable = False
    
    term = ''
    command = None
    for currentArg in args:
        if currentArg in COMMANDS or currentArg.isdigit():
            command, currentArg = choose_command(command, currentArg)
            executable = True
        if currentArg != command and currentArg:
            term += ' {ca}'.format(ca=currentArg)
    term = term.strip()

    if command and command.isdigit():
        if(int(command) < 0):
            command = '0'
        elif (int(command) > 100):
            command = '100'
            
    results = hunterdouglas.find_by_name(kind, term)
    for result in results:
        label = result["name"]
        internal_id = result["id"]

        if len(term) > 0:
            if not term.lower() in label.lower():
                continue

        arg = "{kind}.{internal_id}.{command}".format(kind=kind, internal_id=internal_id, command=command)
        verb = VERBS[kind]

        executable=True
        if kind != "scenes" and not command:
            executable = False
            title = "{verb} {target}".format(verb=verb, target=label)
        elif kind != "scenes" and command in COMMANDS:
            title = "{verb} {command} {target}".format(verb=verb, command=command, target=label)
        elif kind != "scenes" and command.isdigit():
            title = "{verb} {target} to {command}% up".format(verb=verb, command=command, target=label)
        elif kind == "scenes":
            title = "{verb} {target}".format(verb=verb, target=label)
            
        if title:
            feedback_list.append({'title':title, 'subtitle':label, 'arg':arg, 'valid':executable, 'autocomplete':' {l} '.format(l=label)})    

    feedback_list = sorted(feedback_list, key=lambda k:k['subtitle'])
    for item in feedback_list:
        feedback.addItem(title=item['title'], subtitle=item['subtitle'], arg=item['arg'], valid=item['valid'], autocomplete=item['autocomplete'])
    
    return feedback
示例#2
0
def login_command(query=""):
    stop()

    feedback = Feedback()

    if os.path.isfile("token.txt"):
        tokenFile = open("token.txt")
        token = tokenFile.read()
        tokenFile.close()
        if token.__len__() > 0:
            feedback.addItem(title="You are already authenticated with SmartThings")
            return feedback
    else:
        feedback.addItem(title="Authenticate with SmartThings",
                         subtitle="You will be forwarded to https://www.smartthings.com")
        return feedback
示例#3
0
def list_collector(query=""):
    feedback = Feedback()
    query = query.lower().strip()
    parts = query.split(' ')
    password = len(parts) > 1 and parts[1] or ''
    query = parts[0].strip()
    if not query or "stay".startswith(query):
      feedback.addItem(title="Stay", subtitle="Arm in Stay mode", arg="stay "+password, valid=True, autocomplete="Stay "+password)
    if not query or "away".startswith(query):
      feedback.addItem(title="Away", subtitle="Arm in Away mode", arg="away "+password, valid=True, autocomplete="Away "+password)
    if not query or "off".startswith(query):
      feedback.addItem(title="Off", subtitle="Disarm the Alarm", arg="off "+password, valid=True, autocomplete=" Off "+password)
    
    return feedback
示例#4
0
    devices.list()
    exit(0)
if error is not None and "no devices" in error:
    devices.list()
    exit(0)
result = os.popen(cmd).read().strip()
displayName = result.split(' ')[-1][0:-1]
parts = displayName.split("/")
packageName = None
className = None
simpleName = None
if len(parts) > 1:
    packageName = parts[0]
    className = parts[1]
    simpleName = className.split(".")[-1]

if simpleName is not None:
    feedback.addItem(arg=simpleName, title=simpleName, subtitle="Simple Name")
if className is not None:
    feedback.addItem(arg=className, title=className, subtitle="Class Name")
if packageName is not None:
    feedback.addItem(arg=packageName,
                     title=packageName,
                     subtitle="Package Name")
if displayName is not None:
    feedback.addItem(arg=displayName,
                     title=displayName,
                     subtitle="Full String")

print feedback.get()
示例#5
0
def device_collector(query=""):
    stop()

    feedback = Feedback()

    args = string.split(query, " ")

    command = args[-1]
    if len(command) < 1:
        command = args[-2]

    switchCommandsFile = open("commands.switches.txt")
    switchCommands = switchCommandsFile.read()
    switchCommandsFile.close()

    lockCommandsFile = open("commands.locks.txt")
    lockCommands = lockCommandsFile.read()
    lockCommandsFile.close()

    executable = False
    if command in switchCommands or command in lockCommands:
        if len(command) > 0:
            executable = True
    else:
        command = ''

    deviceFilter = ''
    for currentArg in args:
        if currentArg != command:
            deviceFilter += ' {ca}'.format(ca=currentArg)

    deviceFilter = deviceFilter.strip()

    tokenFile = open("token.txt")
    token = tokenFile.read()
    tokenFile.close()

    with open("endpoints.txt", 'r') as fh:
        try:
            deviceFile = open("devices.txt")
            for deviceDataString in deviceFile.readlines():
                deviceData = string.split(deviceDataString, ":")
                deviceEndpoint = deviceData[0].strip()
                deviceLabel = deviceData[1].strip()

                if len(deviceFilter) > 0:
                    if not deviceFilter.lower() in deviceLabel.lower():
                        continue

                arg = "{deviceEndpoint}.{command}".format(
                    deviceEndpoint=deviceEndpoint, command=command)

                title = deviceLabel
                if command.__len__() > 1:
                    if command in switchCommands:
                        title = "Turn {command} {device}".format(
                            command=command, device=deviceLabel)
                    else:
                        title = "{command} {device}".format(
                            command=command.capitalize(), device=deviceLabel)

                feedback.addItem(title=title,
                                 subtitle=deviceLabel,
                                 arg=arg,
                                 valid=executable,
                                 autocomplete=' {l}'.format(l=deviceLabel))

            deviceFile.close()
        except IOError:
            print "Uh oh"

    return feedback
def device_collector(query=""):
    stop()

    feedback = Feedback()

    args = string.split(query, " ")

    command = args[-1]
    if len(command) < 1:
        command = args[-2]

    switchCommandsFile = open("commands.switches.txt")
    switchCommands = switchCommandsFile.read()
    switchCommandsFile.close()
    
    lockCommandsFile = open("commands.locks.txt")
    lockCommands = lockCommandsFile.read()
    lockCommandsFile.close()
    
    executable = False
    if command in switchCommands or command in lockCommands:
        if len(command) > 0:
            executable = True
    else:
        command = ''
    
    deviceFilter = ''
    for currentArg in args:
        if currentArg != command:
            deviceFilter += ' {ca}'.format(ca=currentArg)

    deviceFilter = deviceFilter.strip()

    tokenFile = open("token.txt")
    token = tokenFile.read()
    tokenFile.close()

    with open("endpoints.txt", 'r') as fh:
        try:
            deviceFile = open("devices.txt")
            for deviceDataString in deviceFile.readlines():
                deviceData = string.split(deviceDataString, ":")
                deviceEndpoint = deviceData[0].strip()
                deviceLabel = deviceData[1].strip()
    
                if len(deviceFilter) > 0:
                    if not deviceFilter.lower() in deviceLabel.lower():
                        continue
    
                arg = "{deviceEndpoint}.{command}".format(deviceEndpoint=deviceEndpoint, command=command)
                
                title = deviceLabel
                if command.__len__() > 1:
                    if command in switchCommands:
                        title = "Turn {command} {device}".format(command=command, device=deviceLabel)
                    else:
                        title = "{command} {device}".format(command=command.capitalize(), device=deviceLabel)
    
                feedback.addItem(title=title, subtitle=deviceLabel, arg=arg, valid=executable, autocomplete=' {l}'.format(l=deviceLabel))
            
            deviceFile.close()
        except IOError:
            print "Uh oh"
    
    return feedback