Fix disconnect handling

The code previously assumed that a disconnect would only occur after a successful handshake, and so would do a non-safe lookup of the switch id for the given connection. When disconnects happen in the middle of the handshake, this would crash the program.

The solution is to perform a safe check and update the platform state depending on whether or not the switch handshake is done or not.