Method to call to cleanly terminate the connection to the device.

def cleanup(self):
        """Method to call to cleanly terminate the connection to the device.
        """
        if self.transport:
            self.transport.close()
            self.transport = None
        if self.task:
            self.task.cancel()
            self.task = None