async def connect(self):
import serial<EOL>log.info('<STR_LIT>')<EOL>protocol = partial(<EOL>ProxyProtocol,<EOL>disconnect_callback=self.reconnect,<EOL>raw_callback=self.raw_callback,<EOL>loop=self.loop,<EOL>)<EOL>if self.host:<EOL><INDENT>connection = self.loop.create_connection(protocol, self.host, self.port)<EOL><DEDENT>else:<EOL><INDENT>connection = create_serial_connection(self.loop, protocol, self.port, self.baud)<EOL><DEDENT>try:<EOL><INDENT>with async_timeout.timeout(CONNECTION_TIMEOUT,<EOL>loop=self.loop):<EOL><INDENT>self.transport, self.protocol = await connection<EOL><DEDENT><DEDENT>except (serial.serialutil.SerialException, ConnectionRefusedError,<EOL>TimeoutError, OSError, asyncio.TimeoutError) as exc:<EOL><INDENT>reconnect_interval = DEFAULT_RECONNECT_INTERVAL<EOL>log.error(<EOL>"<STR_LIT>",<EOL>reconnect_interval)<EOL>self.loop.call_later(reconnect_interval, self.reconnect, exc)<EOL>return<EOL><DEDENT>log.info('<STR_LIT>')<EOL>
Set up connection and hook it into HA for reconnect/shutdown.