Exemplo n.º 1
0
def set_bridge(bridge_ip=None):
    try:
        if not bridge_ip:
            bridge_ip = utils.search_for_bridge()

            if not bridge_ip:
                print('No bridges found on your network. Try specifying the IP address.'.encode('utf-8'))
                return None

        workflow = Workflow()

        # Create API user for the workflow
        r = requests.post(
            'http://{bridge_ip}/api'.format(bridge_ip=bridge_ip),
            data=json.dumps({'devicetype': 'Alfred 2'}),
            timeout=3
        )

        resp = r.json()[0]

        if resp.get('error'):
            print('Setup Error: %s' % resp['error'].get('description').encode('utf-8'))
        else:
            workflow.settings['bridge_ip'] = bridge_ip
            workflow.settings['username'] = resp['success']['username']

            print('Success! You can now control your lights by using the "hue" keyword.'.encode('utf-8'))

    except requests.exceptions.RequestException:
        print('Connection error.'.encode('utf-8'))
Exemplo n.º 2
0
def set_bridge(bridge_ip=None):
    try:
        if not bridge_ip:
            bridge_ip = utils.search_for_bridge()

            if not bridge_ip:
                print(
                    'No bridges found on your network. Try specifying the IP address.'
                    .encode('utf-8'))
                return None

        workflow = Workflow()

        # Create API user for the workflow
        r = requests.post('http://{bridge_ip}/api'.format(bridge_ip=bridge_ip),
                          data=json.dumps({'devicetype': 'Alfred 2'}),
                          timeout=3)

        resp = r.json()[0]

        if resp.get('error'):
            print('Setup Error: %s' %
                  resp['error'].get('description').encode('utf-8'))
        else:
            workflow.settings['bridge_ip'] = bridge_ip
            workflow.settings['username'] = resp['success']['username']

            print(
                'Success! You can now control your lights by using the "hue" keyword.'
                .encode('utf-8'))

    except requests.exceptions.RequestException:
        print('Connection error.'.encode('utf-8'))
Exemplo n.º 3
0
                        autocomplete='groups:%s:harmony:tetrad:' % id)

                    self._add_item(
                        title='Split Complementary',
                        subtitle='Colors that are opposite and adjacent.',
                        icon='split_complementary.png',
                        autocomplete='groups:%s:harmony:split_complementary:' % id)

        self._filter_items()
        return self.items


def main(workflow):
    if workflow.update_available:
        workflow.add_item(
            'New version available!',
            'Press enter to install the update.',
            autocomplete='workflow:update')
    hue_index_filter = HueIndexFilter(workflow)
    items = hue_index_filter.get_items()
    for item in items:
        i = workflow.add_item(**item)
    workflow.send_feedback()


if __name__ == '__main__':
    workflow = Workflow(update_settings={
        'github_slug': 'benknight/hue-alfred-workflow',
    })
    sys.exit(workflow.run(main))
Exemplo n.º 4
0
            endpoint = '/scenes'
            data = {'name': value, 'lights': lids, 'recycle': False}

        else:
            return

        # Make the request
        self.hue_request.request(method, endpoint, json.dumps(data))

        return


def main(workflow):
    query = workflow.args[0].split(':')

    if query[0] == 'set_bridge':
        bridge_ip = query[1]
        setup.set_bridge(bridge_ip)
    else:
        action = HueAction()
        try:
            action.execute(query)
            print(('Action completed! <%s>' % workflow.args[0]).encode('utf-8'))
        except ValueError:
            pass


if __name__ == '__main__':
    workflow = Workflow()
    sys.exit(workflow.run(main))