def get_state(api, entity_id):
    """Query given API for state of entity_id."""
    try:
        req = api(METHOD_GET, URL_API_STATES_ENTITY.format(entity_id))

        # req.status_code == 422 if entity does not exist

        return ha.State.from_dict(req.json()) \
            if req.status_code == 200 else None

    except (HomeAssistantError, __HOLE__):
        # ValueError if req.json() can't parse the json
        _LOGGER.exception("Error fetching state")

        return None
dataset/ETHPy150Open home-assistant/home-assistant/homeassistant/remote.py/get_state