(self)
return self.roomba_connected
Connect to Roomba MQTT server
Connect to Roomba MQTT server
Connect to Roomba MQTT server
async def async_connect(self):
        '''
        Connect to Roomba MQTT server
        '''
        if not all([self.address, self.blid, self.password]):
            self.log.critical("Invalid address, blid, or password! All these "
                              "must be specified!")
            return False
        count = 0
        max_retries = 3
        retry_timeout = 1
        while not self.roomba_connected:
            try:
                if self.client is None:
                    self.log.info("Connecting...")
                    self.setup_client()
                    await self.loop.run_in_executor(None, self.client.connect, self.address, self.roomba_port, 60)
                else:
                    self.log.info("Attempting to Reconnect...")
                    self.client.loop_stop()
                    await self.loop.run_in_executor(None, self.client.reconnect)
                self.client.loop_start()
                await self.event_wait(self.is_connected, 1)    #wait for MQTT on_connect to fire (timeout 1 second)
            except (ConnectionRefusedError, OSError) as e:
                if e.errno == 111:      #errno.ECONNREFUSED
                    self.log.error('Unable to Connect to roomba {}, make sure nothing else is connected (app?), '
                                   'as only one connection at a time is allowed'.format(self.roombaName))
                elif e.errno == 113:    #errno.No Route to Host
                    self.log.error('Unable to contact roomba {} on ip {}'.format(self.roombaName, self.address))
                else:
                    self.log.error("Connection Error: {} ".format(e))
                
                await asyncio.sleep(retry_timeout)
                self.log.error("Attempting retry Connection# {}".format(count))
                
                count += 1
                if count >= max_retries:
                    retry_timeout = 60
                    
            except asyncio.CancelledError:
                self.log.error('Connection Cancelled')
                break
            except Exception as e:
                #self.log.error("Error: {} ".format(e))
                self.log.exception(e)
                if count >= max_retries:
                    break
            
        if not self.roomba_connected:   
            self.log.error("Unable to connect to {}".format(self.roombaName))
        return self.roomba_connected
async def async_connect ( self ) : if not all ( [ self . address , self . blid , self . password ] ) : self . log . critical ( "Invalid address, blid, or password! All these " "must be specified!" ) return False count = 0 max_retries = 3 retry_timeout = 1 while not self . roomba_connected : try : if self . client is None : self . log . info ( "Connecting..." ) self . setup_client ( ) await self . loop . run_in_executor ( None , self . client . connect , self . address , self . roomba_port , 60 ) else : self . log . info ( "Attempting to Reconnect..." ) self . client . loop_stop ( ) await self . loop . run_in_executor ( None , self . client . reconnect ) self . client . loop_start ( ) await self . event_wait ( self . is_connected , 1 ) #wait for MQTT on_connect to fire (timeout 1 second) except ( ConnectionRefusedError , OSError ) as e : if e . errno == 111 : #errno.ECONNREFUSED self . log . error ( 'Unable to Connect to roomba {}, make sure nothing else is connected (app?), ' 'as only one connection at a time is allowed' . format ( self . roombaName ) ) elif e . errno == 113 : #errno.No Route to Host self . log . error ( 'Unable to contact roomba {} on ip {}' . format ( self . roombaName , self . address ) ) else : self . log . error ( "Connection Error: {} " . format ( e ) ) await asyncio . sleep ( retry_timeout ) self . log . error ( "Attempting retry Connection# {}" . format ( count ) ) count += 1 if count >= max_retries : retry_timeout = 60 except asyncio . CancelledError : self . log . error ( 'Connection Cancelled' ) break except Exception as e : #self.log.error("Error: {} ".format(e)) self . log . exception ( e ) if count >= max_retries : break if not self . roomba_connected : self . log . error ( "Unable to connect to {}" . format ( self . roombaName ) ) return self . roomba_connected