def run(self):
    """Main thread function to maintain connection and receive remote status."""
    _LOGGER.info("Started")
    while True:
      self._maybe_reconnect()
      line = ''
      try:
        # If someone is sending a command, we can lose our connection so grab a
        # copy beforehand. We don't need the lock because if the connection is
        # open, we are the only ones that will read from telnet (the reconnect
        # code runs synchronously in this loop).
        t = self._telnet
        if t is not None:
          line = t.read_until(b"\n")
      except EOFError:
        try:
          self._lock.acquire()
          self._disconnect_locked()
          continue
        finally:
          self._lock.release()
      self._recv_cb(line.decode('ascii').rstrip())
Main thread function to maintain connection and receive remote status.