def _initsession(self, host=None, port=None, username=None, password=None, uri=None, cleansession=None) -> dict: # Load config broker_conf = self.config.get('broker', dict()).copy() if 'mqtt' not in broker_conf: broker_conf['scheme'] = 'mqtt' if 'username' not in broker_conf: broker_conf['username'] = None if 'password' not in broker_conf: broker_conf['password'] = None if uri is not None: result = urlparse(uri) if result.scheme: broker_conf['scheme'] = result.scheme if result.hostname: broker_conf['host'] = result.hostname if result.port: broker_conf['port'] = result.port if result.username: broker_conf['username'] = result.username if result.password: broker_conf['password'] = result.password if host: broker_conf['host'] = host if port: broker_conf['port'] = int(port) if username: broker_conf['username'] = username if password: broker_conf['password'] = password if cleansession is not None: broker_conf['cleansession'] = cleansession for key in ['scheme', 'host', 'port']: if not_in_dict_or_none(broker_conf, key): raise ClientException("Missing connection parameter '%s'" % key) s = Session() s.client_id = self.client_id s.remote_address = broker_conf['host'] s.remote_port = broker_conf['port'] s.username = broker_conf['username'] s.password = broker_conf['password'] s.scheme = broker_conf['scheme'] if cleansession is not None: s.cleansession = cleansession else: s.cleansession = self.config.get('cleansession', True) s.keep_alive = self.config['keep_alive'] if 'will' in self.config: s.will_flag = True s.will_retain = self.config['will']['retain'] s.will_topic = self.config['will']['topic'] s.will_message = self.config['will']['message'] else: s.will_flag = False s.will_retain = False s.will_topic = None s.will_message = None return s
def _initsession(self, uri=None, cleansession=None, cafile=None, capath=None, cadata=None) -> Session: # Load config broker_conf = self.config.get("broker", dict()).copy() if uri: broker_conf["uri"] = uri if cafile: broker_conf["cafile"] = cafile elif "cafile" not in broker_conf: broker_conf["cafile"] = None if capath: broker_conf["capath"] = capath elif "capath" not in broker_conf: broker_conf["capath"] = None if cadata: broker_conf["cadata"] = cadata elif "cadata" not in broker_conf: broker_conf["cadata"] = None if cleansession is not None: broker_conf["cleansession"] = cleansession for key in ["uri"]: if not_in_dict_or_none(broker_conf, key): raise ClientException("Missing connection parameter '%s'" % key) s = Session() s.broker_uri = uri s.client_id = self.client_id s.cafile = broker_conf["cafile"] s.capath = broker_conf["capath"] s.cadata = broker_conf["cadata"] if cleansession is not None: s.clean_session = cleansession else: s.clean_session = self.config.get("cleansession", True) s.keep_alive = self.config["keep_alive"] - self.config["ping_delay"] if "will" in self.config: s.will_flag = True s.will_retain = self.config["will"]["retain"] s.will_topic = self.config["will"]["topic"] s.will_message = self.config["will"]["message"] s.will_qos = self.config["will"]["qos"] else: s.will_flag = False s.will_retain = False s.will_topic = None s.will_message = None return s
def _initsession(self, uri=None, cleansession=None, cafile=None, capath=None, cadata=None) -> Session: # Load config broker_conf = self.config.get('broker', dict()).copy() if uri: broker_conf['uri'] = uri if cafile: broker_conf['cafile'] = cafile elif 'cafile' not in broker_conf: broker_conf['cafile'] = None if capath: broker_conf['capath'] = capath elif 'capath' not in broker_conf: broker_conf['capath'] = None if cadata: broker_conf['cadata'] = cadata elif 'cadata' not in broker_conf: broker_conf['cadata'] = None if cleansession is not None: broker_conf['cleansession'] = cleansession for key in ['uri']: if not_in_dict_or_none(broker_conf, key): raise ClientException("Missing connection parameter '%s'" % key) s = Session() s.broker_uri = uri s.client_id = self.client_id s.cafile = broker_conf['cafile'] s.capath = broker_conf['capath'] s.cadata = broker_conf['cadata'] if cleansession is not None: s.clean_session = cleansession else: s.clean_session = self.config.get('cleansession', True) s.keep_alive = self.config['keep_alive'] - self.config['ping_delay'] if 'will' in self.config: s.will_flag = True s.will_retain = self.config['will']['retain'] s.will_topic = self.config['will']['topic'] s.will_message = self.config['will']['message'] s.will_qos = self.config['will']['qos'] else: s.will_flag = False s.will_retain = False s.will_topic = None s.will_message = None return s
def _initsession( self, uri=None, cleansession=None, cafile=None, capath=None, cadata=None) -> Session: # Load config broker_conf = self.config.get('broker', dict()).copy() if uri: broker_conf['uri'] = uri if cafile: broker_conf['cafile'] = cafile elif 'cafile' not in broker_conf: broker_conf['cafile'] = None if capath: broker_conf['capath'] = capath elif 'capath' not in broker_conf: broker_conf['capath'] = None if cadata: broker_conf['cadata'] = cadata elif 'cadata' not in broker_conf: broker_conf['cadata'] = None if cleansession is not None: broker_conf['cleansession'] = cleansession for key in ['uri']: if not_in_dict_or_none(broker_conf, key): raise ClientException("Missing connection parameter '%s'" % key) s = Session() s.broker_uri = uri s.client_id = self.client_id s.cafile = broker_conf['cafile'] s.capath = broker_conf['capath'] s.cadata = broker_conf['cadata'] if cleansession is not None: s.clean_session = cleansession else: s.clean_session = self.config.get('cleansession', True) s.keep_alive = self.config['keep_alive'] - self.config['ping_delay'] if 'will' in self.config: s.will_flag = True s.will_retain = self.config['will']['retain'] s.will_topic = self.config['will']['topic'] s.will_message = self.config['will']['message'] s.will_qos = self.config['will']['qos'] else: s.will_flag = False s.will_retain = False s.will_topic = None s.will_message = None return s