def is_state(api, entity_id, state):
    cur_state = get_state(api, entity_id)

    return cur_state and cur_state.state == state
Query API to see if entity_id is specified state.
dataset/ETHPy150Open home-assistant/home-assistant/homeassistant/remote.py/is_state