#!/usr/bin/env python3 # # Copyright 2019, Mischa Peters , High5!. # Version 1.0 - 20191227 # # Create a new user on the bridge # # For example: # $ add-newdeveloper.py # # Follow the steps at the Hue Developer site to get the username/token # https://developers.meethue.com/develop/get-started-2/ # # Requires: # - Python >3.6 # import argparse import ssl import urllib.request import json parser = argparse.ArgumentParser(description="Create a new developer token on the Hue Bridge") parser.add_argument("bridge", type=str, help="Hue Bridge IP address") try: args = parser.parse_args() bridge = args.bridge except argparse.ArgumentError as e: print(str(e)) no_cert_check = ssl.create_default_context() no_cert_check.check_hostname=False no_cert_check.verify_mode=ssl.CERT_NONE data = b'{"devicetype": "my_hue_app#device"}' url = f"https://{bridge}/api" req = urllib.request.Request(url=url, data=data, method='POST') with urllib.request.urlopen(req, context=no_cert_check) as response: content = response.read() json_data = json.loads(content) print (f"{json_data}")