code: def _disconnect(self):
          
          if not self.protocol or not self.protocol.transport:
              self.protocol = None  # Make sure protocol is None
              return
          _LOGGER.info('Disconnecting from gateway')
          self.protocol.transport.close()
          self.protocol = None
docs: Disconnect from the transport.