#NEWLINE# def setup_platform( hass , config , add_devices , discovery_info = None ) : #NEWLINE# #INDENT# 'Setup the aREST binary sensor.' #NEWLINE# resource = config . get ( CONF_RESOURCE ) #NEWLINE# pin = config . get ( CONF_PIN ) #NEWLINE# sensor_class = config . get ( 'sensor_class' ) #NEWLINE# if ( sensor_class not in SENSOR_CLASSES ) : #NEWLINE# #INDENT# _LOGGER . warning ( 'Unknown sensor class: %s' , sensor_class ) #NEWLINE# sensor_class = None #NEWLINE# #UNINDENT# if ( None in ( resource , pin ) ) : #NEWLINE# #INDENT# _LOGGER . error ( 'Not all required config keys present: %s' , ', ' . join ( ( CONF_RESOURCE , CONF_PIN ) ) ) #NEWLINE# return False #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# response = requests . get ( resource , timeout = 10 ) . json ( ) #NEWLINE# #UNINDENT# except requests . exceptions . MissingSchema : #NEWLINE# #INDENT# _LOGGER . error ( 'Missing resource or schema in configuration. Add http:// to your URL.' ) #NEWLINE# return False #NEWLINE# #UNINDENT# except requests . exceptions . ConnectionError : #NEWLINE# #INDENT# _LOGGER . error ( 'No route to device at %s. Please check the IP address in the configuration file.' , resource ) #NEWLINE# return False #NEWLINE# #UNINDENT# arest = ArestData ( resource , resource ) #NEWLINE# add_devices ( [ ArestBinarySensor ( arest , resource , config . get ( 'name' , response [ 'name' ] ) , sensor_class , pin ) ] )