#NEWLINE# def setup_platform( hass , config , add_devices , discovery_info = None ) : #NEWLINE# #INDENT# 'Setup the Dweet sensor.' #NEWLINE# import dweepy #NEWLINE# device = config . get ( 'device' ) #NEWLINE# value_template = config . get ( CONF_VALUE_TEMPLATE ) #NEWLINE# if ( None in ( device , value_template ) ) : #NEWLINE# #INDENT# _LOGGER . error ( 'Not all required config keys present: %s' , ', ' . join ( CONF_DEVICE , CONF_VALUE_TEMPLATE ) ) #NEWLINE# return False #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# content = json . dumps ( dweepy . get_latest_dweet_for ( device ) [ 0 ] [ 'content' ] ) #NEWLINE# #UNINDENT# except dweepy . DweepyError : #NEWLINE# #INDENT# _LOGGER . error ( "Device/thing '%s' could not be found" , device ) #NEWLINE# return False #NEWLINE# #UNINDENT# if ( template . render_with_possible_json_value ( hass , value_template , content ) is '' ) : #NEWLINE# #INDENT# _LOGGER . error ( "'%s' was not found" , value_template ) #NEWLINE# return False #NEWLINE# #UNINDENT# dweet = DweetData ( device ) #NEWLINE# add_devices ( [ DweetSensor ( hass , dweet , config . get ( 'name' , DEFAULT_NAME ) , value_template , config . get ( 'unit_of_measurement' ) ) ] )