How many connected devices do you have? How often do you add/remove some?
I feel like this whole scenario could be solved by a very ugly switch case generated by deepseek for 0.02ct.