#NEWLINE# def get_state( api , entity_id ) : #NEWLINE# #INDENT# 'Query given API for state of entity_id.' #NEWLINE# try : #NEWLINE# #INDENT# req = api ( METHOD_GET , URL_API_STATES_ENTITY . format ( entity_id ) ) #NEWLINE# return ( ha . State . from_dict ( req . json ( ) ) if ( req . status_code == 200 ) else None ) #NEWLINE# #UNINDENT# except ( HomeAssistantError , ValueError ) : #NEWLINE# #INDENT# _LOGGER . exception ( 'Error fetching state' ) #NEWLINE# return None