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 broker_conf.get(key, None) is None: raise ClientException("Missing connection parameter '%s'" % key) s = Session(self.plugins_manager) s.broker_uri = broker_conf["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(self.plugins_manager) s.broker_uri = broker_conf['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