def mock_state_change_event(hass, new_state, old_state=None):
    event_data = {
        'entity_id': new_state.entity_id,
        'new_state': new_state,
    }

    if old_state:
        event_data['old_state'] = old_state

    hass.bus.fire(EVENT_STATE_CHANGED, event_data)
Mock state change envent.
dataset/ETHPy150Open home-assistant/home-assistant/tests/common.py/mock_state_change_event