def main(wf):

    ####################################################################
    # Get init data
    ####################################################################
    password = util.getPassword(wf)
    url = util.getURL(wf)

    ####################################################################
    # Fetch all data in background if the query is empty
    ####################################################################

    sys.stderr.write('query : ' + str(wf.args) + '\n')
    sys.stderr.write('el : ' + str(wf.args[0]) + '\n')
    sys.stderr.write('action : ' + str(wf.args[1]) + '\n')

    pin = ''
    if len(wf.args) == 3:
        sys.stderr.write('pin : ' + str(wf.args[2]) + '\n')
        pin = wf.args[2]

    query = wf.args[0].split(' ')

    data = util.getData(wf, 'alarm_control_panel')
    item = data[wf.args[0]]

    res = [{
        'name': 'Enter Pin Code and press <Enter>'
    }]

    # Loop through the returned posts and add an item for each to
    # the list of results for Alfred
    #for post in posts:

    for post in res:
        sys.stderr.write("post : " + str(post) + '\n')

        wf.add_item(
            title=post['name'],
            subtitle='',
            valid=True,
            arg=wf.args[0] + ' ' + wf.args[1] + ' ' + pin,
            #arg='https://browall.duckdns.org:8123/api/services/automation/trigger?api_password=DrumNBass1111',
            icon=icon.getIcon('mdi:alarm', 'w'))

        # Send the results to Alfred as XML
    wf.send_feedback()

    return 0
def main(wf):

	####################################################################
     # Get init data
    ####################################################################
    parser = argparse.ArgumentParser()
    parser.add_argument('query', nargs='?', default=None)
    args = parser.parse_args(wf.args)

    password = util.getPassword(wf);
    url = util.getURL(wf);

     ####################################################################
     # Fetch all data in background if the query is empty
     ####################################################################
    if args.query == None:
        if not is_running('update'):
            cmd = ['/usr/bin/python', wf.workflowfile('update_data.py')]
            run_in_background('update', cmd)

    data = util.getData(wf, 'sensor')

    def search_key_for_post(post):
        """Generate a string search key for a post"""
        item = data[post]

        elements = []
        elements.append(item['name'])  # title of post
        elements.append(item['friendly_name'])
        elements.append(item['entity_id'])
        elements.append(item['unit'])
        elements.append(item['search_words'])

        if 'icon' in item.keys():
            #sys.stderr.write("icon : " + str(item['icon']) + '\n')

            icon = item['icon'].split(':')
            if(len(icon) == 2):
                elements.append(icon[1])


        return u' '.join(elements)

    def wrapper():
        return data

    posts = wf.cached_data('allSensors', wrapper, max_age=1)

    # If script was passed a query, use it to filter posts
    if args.query and data:
    	posts = wf.filter(args.query, data, key=search_key_for_post, min_score=20)

    if not posts:  # we have no data to show, so show a warning and stop
        wf.add_item('No posts found', icon=ICON_WARNING)
        wf.send_feedback()
        return 0

    if wf.update_available:
        # Add a notification to top of Script Filter results
        wf.add_item('New version available',
                    'Action this item to install the update',
                    autocomplete='workflow:update',
                    icon=ICON_INFO)

    # Loop through the returned posts and add an item for each to
    # the list of results for Alfred
    #for post in posts:

    for post in posts:
        #sys.stderr.write("post : " + str(post) + '\n')
        item = data[post];

        ICON = icon.getIcon(item['icon'], 'w');

        wf.add_item(title=item['friendly_name'] + ' : ' + item['state'] + ' ' + item['unit'],
                    subtitle=item['entity_id'],
                    valid=False,
                    arg=item['entity_id'],
                    icon=ICON)

    # Send the results to Alfred as XML
    wf.send_feedback()
    return 0;
def main(wf):

    ####################################################################
    # Get init data
    ####################################################################
    password = util.getPassword(wf)
    url = util.getURL(wf)

    ####################################################################
    # Fetch all data in background if the query is empty
    ####################################################################

    sys.stderr.write('query : ' + str(wf.args) + '\n')
    sys.stderr.write('el : ' + str(wf.args[0]) + '\n')

    query = wf.args[0].split(' ')

    data = util.getData(wf, 'alarm_control_panel')
    item = data[wf.args[0]]

    def search_key_for_post(post):
        elements = []
        elements.append(post['name'])
        elements.append(post['value'])
        return u' '.join(elements)

    # If script was passed a query, use it to filter posts
    if item['state'] == 'disarmed':
        res = [{
            'name': 'Arm home',
            'value': 'arm_home'
        }, {
            'name': 'Arm away',
            'value': 'arm_away'
        }]
    else:
        res = [{
            'name': 'Disarmed',
            'value': 'disarmed'
        }]

    if not res:  # we have no data to show, so show a warning and stop
        wf.add_item('No posts found', icon=ICON_WARNING)
        wf.send_feedback()
        return 0

    # Loop through the returned posts and add an item for each to
    # the list of results for Alfred
    #for post in posts:

    for post in res:
        sys.stderr.write("post : " + str(post) + '\n')

        wf.add_item(
            title=post['name'],
            subtitle='',
            valid=True,
            arg=wf.args[0] + " " + post['value'],
            #arg='https://browall.duckdns.org:8123/api/services/automation/trigger?api_password=DrumNBass1111',
            icon=icon.getIcon('mdi:alarm', 'w'))

        # Send the results to Alfred as XML
    wf.send_feedback()

    return 0
def main(wf):

    ####################################################################
     # Get init data
    ####################################################################
    parser = argparse.ArgumentParser()
    parser.add_argument('query', nargs='?', default=None)
    args = parser.parse_args(wf.args)

    password = util.getPassword(wf);
    url = util.getURL(wf);

     ####################################################################
     # Fetch all data in background if the query is empty
     ####################################################################
    if args.query == None:
        if not is_running('update'):
            cmd = ['/usr/bin/python', wf.workflowfile('update_data.py')]
            run_in_background('update', cmd)

    data = util.getData(wf, 'alarm_control_panel')

    def search_key_for_post(post):
        """Generate a string search key for a post"""
        item = data[post]

        elements = []
        elements.append(item['friendly_name'])
        elements.append(item['entity_id'])

        return u' '.join(elements)

    def wrapper():
        return data

    posts = wf.cached_data('allAAlarms', wrapper, max_age=1)

    # If script was passed a query, use it to filter posts
    if args.query and data:
        posts = wf.filter(args.query, data, key=search_key_for_post, min_score=20)

    if not posts:  # we have no data to show, so show a warning and stop
        wf.add_item('No posts found', icon=ICON_WARNING)
        wf.send_feedback()
        return 0

    if wf.update_available:
        # Add a notification to top of Script Filter results
        wf.add_item('New version available',
                    'Action this item to install the update',
                    autocomplete='workflow:update',
                    icon=ICON_INFO)

    # Loop through the returned posts and add an item for each to
    # the list of results for Alfred
    #for post in posts:

    for post in posts:
        sys.stderr.write("post : " + str(post) + '\n')
        item = data[post];
        subtitle = '<Enter> to select alarm'

        wf.add_item(title=item['friendly_name'],
                    subtitle=subtitle,
                    valid=True,
                    arg=item['entity_id'],
                    #arg='https://browall.duckdns.org:8123/api/services/automation/trigger?api_password=DrumNBass1111',
                    icon=icon.getIcon('mdi:alarm','w'))

    # Send the results to Alfred as XML
    wf.send_feedback()
    return 0;
def main(wf):

    ####################################################################
    # Get init data
    ####################################################################
    parser = argparse.ArgumentParser()
    parser.add_argument('query', nargs='?', default=None)
    args = parser.parse_args(wf.args)

    password = util.getPassword(wf)
    url = util.getURL(wf)

    ####################################################################
    # Fetch all data in background if the query is empty
    ####################################################################
    if args.query == None:
        if not is_running('update'):
            cmd = ['/usr/bin/python', wf.workflowfile('update_data.py')]
            run_in_background('update', cmd)

    data = util.getData(wf, 'automation')

    def search_key_for_post(post):
        """Generate a string search key for a post"""
        item = data[post]

        elements = []
        elements.append(item['name'])  # title of post
        elements.append(item['friendly_name'])
        elements.append(item['entity_id'])

        return u' '.join(elements)

    def wrapper():
        return data

    posts = wf.cached_data('allAutomations', wrapper, max_age=1)

    # If script was passed a query, use it to filter posts
    if args.query and data:
        posts = wf.filter(args.query,
                          data,
                          key=search_key_for_post,
                          min_score=20)

    if not posts:  # we have no data to show, so show a warning and stop
        wf.add_item('No posts found', icon=ICON_WARNING)
        wf.send_feedback()
        return 0

    # Loop through the returned posts and add an item for each to
    # the list of results for Alfred
    #for post in posts:

    for post in posts:
        sys.stderr.write("post : " + str(post) + '\n')
        item = data[post]
        subtitle = '<Enter> to trigger automation'

        wf.add_item(title=item['friendly_name'],
                    subtitle=subtitle,
                    valid=True,
                    arg=item['entity_id'],
                    icon=icon.getIcon('mdi:home', 'w'))

    # Send the results to Alfred as XML
    wf.send_feedback()
    return 0