code: def connection_lost(self, exc):
          
          _LOGGER.debug('Connection lost with %s', self.transport)
          if self.gateway.cancel_check_conn:
              self.gateway.cancel_check_conn()
              self.gateway.cancel_check_conn = None
          if exc:
              _LOGGER.error(exc)
              self.conn_lost_callback()
          self.transport = None
docs: Handle lost connection.