Small fixes

Handle more errors, and fix Client.stopListening
This commit is contained in:
Mads Marquart
2020-01-05 20:29:44 +01:00
parent e488f4a7da
commit bc1e3edf17
2 changed files with 12 additions and 3 deletions

View File

@@ -2834,10 +2834,13 @@ class Client(object):
def stopListening(self): def stopListening(self):
"""Stop the listening loop.""" """Stop the listening loop."""
if not self._mqtt:
raise ValueError("Not listening")
self._mqtt.disconnect()
self.listening = False self.listening = False
if not self._mqtt:
return
self._mqtt.disconnect()
# TODO: Preserve the _mqtt object
# Currently, there's some issues when disconnecting
self._mqtt = None
def listen(self, markAlive=None): def listen(self, markAlive=None):
"""Initialize and runs the listening loop continually. """Initialize and runs the listening loop continually.

View File

@@ -91,6 +91,12 @@ class Mqtt:
if "lastIssuedSeqId" in j: if "lastIssuedSeqId" in j:
self._sequence_id = j["lastIssuedSeqId"] self._sequence_id = j["lastIssuedSeqId"]
if "errorCode" in j:
# Known types: ERROR_QUEUE_OVERFLOW | ERROR_QUEUE_NOT_FOUND
# 'F\xfa\x84\x8c\x85\xf8\xbc-\x88 FB_PAGES_INSUFFICIENT_PERMISSION\x00'
log.error("MQTT error code %s received", j["errorCode"])
# TODO: Consider resetting the sync_token and sequence ID here?
log.debug("MQTT payload: %s", j) log.debug("MQTT payload: %s", j)
# Call the external callback # Call the external callback