#NEWLINE# def __init__( self , ip_address = None , port = 80 , scheme = 'http' , device_type = 'bulby' , username = 'bulbysoftware' ) : #NEWLINE# #INDENT# "\n        Connects to a Hue Bridge, if an ip address isn't defined it\n        will use ssdp to discover the bridge on the network. If there\n        are more than one bridge it will raise an Exception.\n        " #NEWLINE# if ( ( len ( username ) < 10 ) or ( len ( username ) > 40 ) ) : #NEWLINE# #INDENT# raise Exception ( 'Username must be between 10 and 40 chars' ) #NEWLINE# #UNINDENT# if ( ip_address is None ) : #NEWLINE# #INDENT# results = discover ( 'IpBridge' ) #NEWLINE# locations = [ x . location for x in results ] #NEWLINE# if ( len ( locations ) > 1 ) : #NEWLINE# #INDENT# raise Exception ( ( 'Found more than one bridge %r' % locations ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( locations ) == 0 ) : #NEWLINE# #INDENT# raise Exception ( 'No bridges found' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# parsed_location = urlparse ( locations [ 0 ] ) #NEWLINE# self . ip_address = parsed_location . hostname #NEWLINE# self . port = int ( parsed_location . port ) #NEWLINE# self . base_url = ( '%s://%s' % ( parsed_location . scheme , parsed_location . netloc ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# self . ip_address = ip_address #NEWLINE# self . port = port #NEWLINE# self . base_url = ( '%s://%s:%s' % ( scheme , ip_address , device_type ) ) #NEWLINE# #UNINDENT# self . device_type = device_type #NEWLINE# self . username = username #NEWLINE# self . _lights = None #NEWLINE# self . connect ( )