Can't get inputs

If I do the below, unity says it’s detecting the controller, but the part that tests the button press never returns true. What’s wrong about the code at the bottom that tests for the press?

  var RightHandDevices = new List<UnityEngine.XR.InputDevice>();
        UnityEngine.XR.InputDevices.GetDevicesAtXRNode(UnityEngine.XR.XRNode.RightHand,
                                                         RightHandDevices);
        if (RightHandDevices.Count == 1)
        {
            UnityEngine.XR.InputDevice device = RightHandDevices[0];
            Debug.Log(string.Format("Device name '{0}' with role '{1}'",
                                    device.name, device.role.ToString()));
        }
      


        if (device.TryGetFeatureValue(UnityEngine.XR.CommonUsages.triggerButton, out triggerValue)&& triggerValue)

        {
            Debug.Log("Trigger button is pressed");
        }

is device null or invalid on the first time you check it?