Add helper function to wait for a specific state