Blob


1 #!/usr/bin/env python3
2 #
3 # Copyright 2019, Mischa Peters <mischa AT high5 DOT nl>, High5!.
4 # Version 1.0 - 20191227
5 #
6 # Create a new user on the bridge
7 #
8 # For example:
9 # $ add-newdeveloper.py <bridge IP>
10 #
11 # Follow the steps at the Hue Developer site to get the username/token
12 # https://developers.meethue.com/develop/get-started-2/
13 #
14 # Requires:
15 # - Python >3.6
16 #
17 import argparse
18 import ssl
19 import urllib.request
20 import json
22 parser = argparse.ArgumentParser(description="Create a new developer token on the Hue Bridge")
23 parser.add_argument("bridge", type=str, help="Hue Bridge IP address")
25 try:
26 args = parser.parse_args()
27 bridge = args.bridge
29 except argparse.ArgumentError as e:
30 print(str(e))
32 no_cert_check = ssl.create_default_context()
33 no_cert_check.check_hostname=False
34 no_cert_check.verify_mode=ssl.CERT_NONE
36 data = b'{"devicetype": "my_hue_app#device"}'
37 url = f"https://{bridge}/api"
38 req = urllib.request.Request(url=url, data=data, method='POST')
39 with urllib.request.urlopen(req, context=no_cert_check) as response:
40 content = response.read()
41 json_data = json.loads(content)
42 print (f"{json_data}")