#NEWLINE# def setup_platform( hass , config , add_devices , discovery_info = None ) : #NEWLINE# #INDENT# 'Setup the MPD platform.' #NEWLINE# daemon = config . get ( 'server' , None ) #NEWLINE# port = config . get ( 'port' , 6600 ) #NEWLINE# location = config . get ( 'location' , 'MPD' ) #NEWLINE# password = config . get ( 'password' , None ) #NEWLINE# import mpd #NEWLINE# try : #NEWLINE# #INDENT# mpd_client = mpd . MPDClient ( ) #NEWLINE# mpd_client . connect ( daemon , port ) #NEWLINE# if ( password is not None ) : #NEWLINE# #INDENT# mpd_client . password ( password ) #NEWLINE# #UNINDENT# mpd_client . close ( ) #NEWLINE# mpd_client . disconnect ( ) #NEWLINE# #UNINDENT# except socket . error : #NEWLINE# #INDENT# _LOGGER . error ( 'Unable to connect to MPD. Please check your settings' ) #NEWLINE# return False #NEWLINE# #UNINDENT# except mpd . CommandError as error : #NEWLINE# #INDENT# if ( 'incorrect password' in str ( error ) ) : #NEWLINE# #INDENT# _LOGGER . error ( 'MPD reported incorrect password. Please check your password.' ) #NEWLINE# return False #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise #NEWLINE# #UNINDENT# #UNINDENT# add_devices ( [ MpdDevice ( daemon , port , location , password ) ] )