It is not just O2 sensors either. I spent 10 years trying to figure out why my car would randomly start idling at 2k. At first I would replace the IAC valve (using OEM) and reset the computer. After a few years of that, I discovered if I just reset the computer (instead of also replacing the valve) that it would go back to idling normally for about 1-2 months. Eventually my automatic would sometimes start hunting gears when off of the gas and coasting down an off ramp from a highway. I messed with a lot of stuff... nothing ever seemed to help other than resetting the computer. I eventually remembered that about 2 years prior to the issue first happening (so nearly 12 years), I had replaced the TPS with a $10 one from autozone just because I felt like it. I went to ford, paid for an OEM one, swapped it and reset the computer... and it was a new car. That was probably 6 years ago, never had a high idle since
There are similar stories from other makes too. My general advice when it comes to sensors or electronics is to just go to the dealer and fork up the cash. It will save your sanity in the long run. Of course the irony is most OEMs don't make their own parts so you'd think an "aftermarket" part would be the same quality-wise. For instance valeo makes the OEM clutches for the mustang and ford just whitelabels them. The valeo kit on rockauto is $100 while from ford it is $600. Thought I could "beat the system" and went with the one from rockauto.... yet it gave me horrible vibration at 1.5k rpm.... so I got to change the clutch again.... You can snoop in my history to so those adventures... So even though ford and other OEMs whitelable parts, there is apparently some cruicial quality control specs that they must also pass. And I guess the ones that don't pass are still "good enough" for autozone, etc.