code: async def connect(self):
          
          import serial
  
          log.info('Initiating Rflink connection')
  
          # Rflink create_rflink_connection decides based on the value of host
          # (string or None) if serial or tcp mode should be used
  
          # Setup protocol
          protocol = partial(
              ProxyProtocol,
              disconnect_callback=self.reconnect,
              raw_callback=self.raw_callback,
              loop=self.loop,
          )
  
          # Initiate serial/tcp connection to Rflink gateway
          if self.host:
              connection = self.loop.create_connection(protocol, self.host, self.port)
          else:
              connection = create_serial_connection(self.loop, protocol, self.port, self.baud)
  
          try:
              with async_timeout.timeout(CONNECTION_TIMEOUT,
                                         loop=self.loop):
                  self.transport, self.protocol = await connection
  
          except (serial.serialutil.SerialException, ConnectionRefusedError,
                  TimeoutError, OSError, asyncio.TimeoutError) as exc:
              reconnect_interval = DEFAULT_RECONNECT_INTERVAL
              log.error(
                  "Error connecting to Rflink, reconnecting in %s",
                  reconnect_interval)
  
              self.loop.call_later(reconnect_interval, self.reconnect, exc)
              return
  
          log.info('Connected to Rflink')
docs: Set up connection and hook it into HA for reconnect/shutdown.