Automatic reconnect support for stateful gateway connections.

Lutron and DSC plugins both have to deal with the fact that they
establish a stateful and (hopefully) long-lived connection to the
gateway hardware; if this goes away (gateway device reboots, network
interruption, etc; especially for Lutron where the repeater will
tolerate one connection per credential and boot off any existing
client if someone else connects with the same credential) so that
the socket is unavailable, they need to reestablish the connection.
(Vera doesn't have to deal with this, since its protocol is stateless,
using a new HTTP connection for each request.)

This change introduces:
- new SgWatchdog class in connections.py, which uses select() to monitor
  all sockets registered with it, and invoke a cleanup routine if
  select() reports they're in an errored state. Actually it's worse
  than this; for the case I care about, closed socket, select() throws
  a socket.error exception that doesn't say which socket caused it,
  so then I reprobe all the sockets one at a time.
- StargateHouse owns and initializes the watchdog.
- Lutron and DSC gateway plugins register their sockets with the
  watchdog, and had the signature of their connect() routines rejiggered
  a bit so they could take advantage of it.

There are some ugly hacks and shortcuts taken here; notably in the
watchdog thread:
- there must be a better way to find out which socket is responsible
  for the socket.error exception, but I couldn't find one.
- cleanup process needs a way to tell the sender and listener threads
  to exit; listener blocks on socket read so that's accomplished by
  making sure the socket is closed (in practice, the listener will be
  the one to notice the problem anyway); sender blocks on Queue.get()
  so we have a nasty hack to force that to return.
- watchdog class has no locking around the notify-list management.
- watchdog class also has no notification around notify-list add,
  so the watcher thread has to wake up often to check for changes.

The last two of these should be easy enough to fix; the first two
less so.
Watchdog improvements.

First, add a lock around manipulation of the watchee list.

Second, redo the exception handling. I want to catch the EBADF result
from an operation on a closed socket and handle that specifically, and
anything else (other instance of socket.error or select.error that does
not have EBADF as the error code, or other exceptions that are not
socket.error or select.error) should get logged without interfering
with our dirty work.

What I'd done before was a misuse of "continue", mistakenly assuming
that Python would execute more than one matching exception handler,
so the targeted one would execute and then the catchall one would
still execute. I actually knew it didn't work this way, but I had just
been looking at some code that did that and thought for a second it
was right. So the continue was meaningless, and other socket.error
exceptions would not have been logged.

The simple fix for this would have been to replace the continue with
"else: log it", but I weary of repetition, especially in the main
watchdog loop where aside from logging, we also had to repeat the
handling of invoking cleanup on bad sockets, whether we discovered
them as a result of select() returning vs throwing an exception.
And the exception handler was there for two reasons: to detect
EBADF, and to avoid crashing out. So in both places I care about
EBADF, I changed this to two nested exception handlers: the inner
one is just around the select call and just handles the EBADF case
and reraises socket.error if the errno was not EBADF; the outer one
logs everything. This gets rid of the repetition.

Finally (and this is what caused me to notice all these problems,
and stick the continue there earlier) is despite all this, I was
seeing the "exception in watchdog thread" fire for the exact case
I'm catching as EBADF; this is what made me think the catchall
exception handler was always being executed. Actually, select() was
throwing two different exceptions, first a select.error and then
a socket.error. The select.error was not getting caught, was making
its way to the generic catchall handler and being logged (NB that
at that point, select.error and socket.error are visually
indistinguishable; both say "error: [Errno 9] Bad file descriptor");
then we loop around and invoke the same select() call again but this
time the exception is socket.error, which I was looking for and would
pass off to detect_bad_sockets. Then detect_bad_sockets calls select()
again, and this time sees only socket.error. This all worked fine but
was confusing me with the extra logging. I could catch select.error
in the outer routine and socket.error in the inner routine but I
find that confusing and fragile, so now I just catch both exceptions
in both places (and in practice it seems to get select.error once
then socket.error afterwards).

Also, make detect_bad_sockets a local helper instead of a member
function. It doesn't need self (and this makes it clearer that it
should operate unlocked on a copy of the socket list, instead of
the main one that needs locking).