Filter out currently unused devices
Right now devices that have only a single unplugged port are visible in the applet and the KCM. For all intents and purposes, these devices are useless as they are inactive and unused. Therefore, let's filter them out so they're not distracting and confusing to the user. An option to see them all again is provided in the KCM on the off chance that a person needs to configure the volume or balance of an unused device before it's used.
This patch is principally aimed at people using hardware where PulseAudio represents multiple input and output sources as separate devices rather than separate ports of the same device. I asked the PA people about this and they said that for certain hardware, it's intentional, and the correct approach is to filter out the unused devices over here . So, that's what this patch does.
Thanks to @nicolasfella for his help with getting the initial prototype working!
Connecting a Bluetooth speaker adds it to both the applet and the KCM, and I can switch between it and the internal speakers with the radio buttons:
Additionally connecting an HDMI television adds it as well, and switching between them works: