Best approach to use this type of 'sensor/switch'?

I'm curious as to why there are two balls in there.