#NEWLINE# def setup( hass , config ) : #NEWLINE# #INDENT# 'Common setup for WeMo devices.' #NEWLINE# import pywemo #NEWLINE# global SUBSCRIPTION_REGISTRY #NEWLINE# SUBSCRIPTION_REGISTRY = pywemo . SubscriptionRegistry ( ) #NEWLINE# SUBSCRIPTION_REGISTRY . start ( ) #NEWLINE# def stop_wemo( event ) : #NEWLINE# #INDENT# 'Shutdown Wemo subscriptions and subscription thread on exit.' #NEWLINE# _LOGGER . info ( 'Shutting down subscriptions.' ) #NEWLINE# SUBSCRIPTION_REGISTRY . stop ( ) #NEWLINE# #UNINDENT# hass . bus . listen_once ( EVENT_HOMEASSISTANT_STOP , stop_wemo ) #NEWLINE# def discovery_dispatch( service , discovery_info ) : #NEWLINE# #INDENT# 'Dispatcher for WeMo discovery events.' #NEWLINE# ( _ , model_name , _ , _ , serial ) = discovery_info #NEWLINE# if ( serial in KNOWN_DEVICES ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# _LOGGER . debug ( 'Discovered unique device %s' , serial ) #NEWLINE# KNOWN_DEVICES . append ( serial ) #NEWLINE# service = ( WEMO_MODEL_DISPATCH . get ( model_name ) or DISCOVER_SWITCHES ) #NEWLINE# component = WEMO_SERVICE_DISPATCH . get ( service ) #NEWLINE# discovery . discover ( hass , service , discovery_info , component , config ) #NEWLINE# #UNINDENT# discovery . listen ( hass , discovery . SERVICE_WEMO , discovery_dispatch ) #NEWLINE# _LOGGER . info ( 'Scanning for WeMo devices.' ) #NEWLINE# devices = [ ( device . host , device ) for device in pywemo . discover_devices ( ) ] #NEWLINE# devices . extend ( ( ( address , None ) for address in config . get ( DOMAIN , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) . get ( 'static' , [ ] ) ) ) #NEWLINE# for ( address , device ) in devices : #NEWLINE# #INDENT# port = pywemo . ouimeaux_device . probe_wemo ( address ) #NEWLINE# if ( not port ) : #NEWLINE# #INDENT# _LOGGER . warning ( 'Unable to probe wemo at %s' , address ) #NEWLINE# continue #NEWLINE# #UNINDENT# _LOGGER . info ( 'Adding wemo at %s:%i' , address , port ) #NEWLINE# url = ( 'http://%s:%i/setup.xml' % ( address , port ) ) #NEWLINE# if ( device is None ) : #NEWLINE# #INDENT# device = pywemo . discovery . device_from_description ( url , None ) #NEWLINE# #UNINDENT# discovery_info = ( device . name , device . model_name , url , device . mac , device . serialnumber ) #NEWLINE# discovery . discover ( hass , discovery . SERVICE_WEMO , discovery_info ) #NEWLINE# #UNINDENT# return True