Skip to content

Commit

Permalink
Merge pull request #142 from congzhou09/master
Browse files Browse the repository at this point in the history
fix:'clean_session' in app.config is not passed to the client
  • Loading branch information
Sohaib90 authored Nov 18, 2023
2 parents 7e4cd95 + fb5c3e0 commit 7db7b55
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions flask_mqtt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ def init_app(self, app: Flask, config_prefix : str = "MQTT") -> None:
else:
self.client._client_id = self.client_id

if config_prefix + "_CLEAN_SESSION" in app.config:
self.clean_session = app.config[config_prefix + "_CLEAN_SESSION"]

self.client._transport = app.config.get(config_prefix + "_TRANSPORT", "tcp").lower()
self.client._protocol = app.config.get(config_prefix + "_PROTOCOL_VERSION", MQTTv311)
self.client._clean_session = self.clean_session
self.client.on_connect = self._handle_connect
self.client.on_disconnect = self._handle_disconnect

if config_prefix + "_CLEAN_SESSION" in app.config:
self.clean_session = app.config[config_prefix + "_CLEAN_SESSION"]

if config_prefix + "_USERNAME" in app.config:
self.username = app.config[ config_prefix + "_USERNAME"]

Expand Down
4 changes: 2 additions & 2 deletions tests/test_flaskmqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_mqtt_config_values(self):
self.app.config['MQTT_BROKER_URL'] = 'broker_url'
self.app.config['MQTT_BROKER_PORT'] = 'broker_port'
self.app.config['MQTT_TLS_ENABLED'] = 'tls_enabled'
self.app.config['MQTT_CLEAN_SESSION'] = True
self.app.config['MQTT_CLEAN_SESSION'] = False
self.app.config['MQTT_KEEPALIVE'] = 'keepalive'
self.app.config['MQTT_LAST_WILL_TOPIC'] = 'home/lastwill'
self.app.config['MQTT_LAST_WILL_MESSAGE'] = 'last will'
Expand All @@ -63,7 +63,7 @@ def test_mqtt_config_values(self):
self.assertEqual('broker_url', mqtt.broker_url)
self.assertEqual('broker_port', mqtt.broker_port)
self.assertEqual('tls_enabled', mqtt.tls_enabled)
self.assertEqual(True, mqtt.clean_session)
self.assertEqual(False, mqtt.clean_session)
self.assertEqual('keepalive', mqtt.keepalive)
self.assertEqual('home/lastwill', mqtt.last_will_topic)
self.assertEqual('last will', mqtt.last_will_message)
Expand Down

0 comments on commit 7db7b55

Please sign in to comment.