How to use the discover.find_hue function in discover

To help you get started, we’ve selected a few discover examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PaulMcMillan / 2014_defcon_timing / hue / reset_users.py View on Github external
#!/usr/bin/env python
import json
import random
from pprint import pprint

import requests

import users
import discover

hue_url = discover.find_hue()

request_dict = {
    "devicetype": "timinguser",
    "username": users.generate_username().next(),
    }
res = requests.post(hue_url + 'api', headers={'Content-Type': 'text/plain'},
                    data=json.dumps(request_dict))
print res.json()
for message in res.json():
    if message.get('error'):
        raise Exception(message['error']['description'])
    if message.get('success'):
        username = message['success']['username']
        with open('username', 'w') as f:
            f.write(username)
github PaulMcMillan / 2014_defcon_timing / hue / collect_data.py View on Github external
"hue": light_color,
                "sat": 255,
                "on": True,
                "bri": 255,
            }
            res = s.put(api_url + 'lights/{}/state'.format(light_id),
                        data=json.dumps(body))
#            pprint(res.json())
            time.sleep(1)
        time.sleep(1)


s = requests.Session()
s.headers = {}  # make our packet smaller. The server ignores headers
#hue_url = 'http://169.254.159.24/'
hue_url = discover.find_hue()

if len(sys.argv) > 1:
    # oh boy, adding options. rewrite this after the talk...
    current_guess = sys.argv[1]
else:
    current_guess = users.USERNAME_PREFIX

count = -1  # hack to parse data first. This lets us restart the process. Sorta
start_time = time.time()
interval = start_time
username_generators = []
def make_username_generators(current_guess):
    results = []
    for next_guess in users.charset():
        results.append(users.generate_username(current_guess + next_guess))
    return results