'Called when a connection has been established (or lost with None).'

def update_connection(self, connection):

    self.connection = connection
    if connection:
        for cmd in self.pending_commands:
            connection.send_command(cmd)
        self.pending_commands = []
