#NEWLINE# @ Throttle ( MIN_TIME_BETWEEN_UPDATES ) #NEWLINE# def update( self ) : #NEWLINE# #INDENT# 'Get the latest data from aREST device.' #NEWLINE# try : #NEWLINE# #INDENT# if ( self . _pin is None ) : #NEWLINE# #INDENT# response = requests . get ( self . _resource , timeout = 10 ) #NEWLINE# self . data = response . json ( ) [ 'variables' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# if ( str ( self . _pin [ 0 ] ) == 'A' ) : #NEWLINE# #INDENT# response = requests . get ( '{}/analog/{}' . format ( self . _resource , self . _pin [ 1 : ] ) , timeout = 10 ) #NEWLINE# self . data = { #NEWLINE# #INDENT# 'value' : response . json ( ) [ 'return_value' ] , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# _LOGGER . error ( 'Wrong pin naming. Please check your configuration file.' ) #NEWLINE# #UNINDENT# #UNINDENT# except TypeError : #NEWLINE# #INDENT# response = requests . get ( '{}/digital/{}' . format ( self . _resource , response . _pin ) , timeout = 10 ) #NEWLINE# self . data = { #NEWLINE# #INDENT# 'value' : response . json ( ) [ 'return_value' ] , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# except requests . exceptions . ConnectionError : #NEWLINE# #INDENT# _LOGGER . error ( 'No route to device %s. Is device offline?' , self . _resource ) #NEWLINE# self . data = { #NEWLINE# #INDENT# 'error' : 'error fetching' , #NEWLINE# #UNINDENT# }