Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def prompt_create_username(bridge_address):
choice = input('No username specified, do you want to create one now? [Y/n]: ')
if choice.lower() in {'', 'y', 'yes'}:
try:
return qhue.create_new_username(bridge_address)
except QhueException as exception:
stderr(f'Exception occurred while creating the username: {exception}')
def __init__(self):
try:
with open('.hueusername') as f:
bridge_data = json.loads(f.read())
except:
logger.warn("Bridge not authorised, need to press the button!")
bridge_data = json.loads(
requests.get('https://www.meethue.com/api/nupnp').text)[0]
bridge_data['username'] = create_new_username(
bridge_data['internalipaddress'])
with open('.hueusername', 'w') as f:
f.write(json.dumps(bridge_data))
self.bridge = Bridge(bridge_data['internalipaddress'], bridge_data['username'])
logger.info("Successfully connected to Hue Bridge {}".format(bridge_data['internalipaddress']))