Skip to content

Commit

Permalink
Documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
eerimoq committed May 11, 2019
1 parent 425a1e6 commit 2efd6bb
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 15 deletions.
18 changes: 18 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,23 @@ Functions and classes
.. autoclass:: mqttools.Client
:members:

.. autoclass:: mqttools.Broker
:members:

.. autoclass:: mqttools.QoS
:members:

.. autoclass:: mqttools.ConnectError
:members:

.. autoclass:: mqttools.SessionResumeError
:members:

.. autoclass:: mqttools.SubscribeError
:members:

.. autoclass:: mqttools.UnsubscribeError
:members:

.. autoclass:: mqttools.TimeoutError
:members:
44 changes: 29 additions & 15 deletions mqttools/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,21 @@ class SessionResumeError(Error):
pass


class ConnectError(Error):
class ReasonError(Error):

def __init__(self, reason):
super().__init__()
self.reason = reason

def __str__(self):
if isinstance(self.reason, enum.Enum):
return f'{self.reason.name}({self.reason.value})'
else:
return f'UNKNOWN({self.reason})'


class ConnectError(ReasonError):

def __str__(self):
message = f'{self.reason.name}({self.reason.value})'

Expand All @@ -51,19 +60,6 @@ def __str__(self):
return message


class ReasonError(Error):

def __init__(self, reason):
super().__init__()
self.reason = reason

def __str__(self):
if isinstance(self.reason, enum.Enum):
return f'{self.reason.name}({self.reason.value})'
else:
return f'UNKNOWN({self.reason})'


class SubscribeError(ReasonError):
pass

Expand Down Expand Up @@ -248,10 +244,16 @@ async def start(self, resume_session=False):
or `subscribe()` calls. Call `stop()` to close the connection.
If `resume_session` is ``True``, the client tries to resume
the last session in the broker. A `SessionResumeError`
the last session in the broker. A :class:`SessionResumeError`
exception is raised if the resume fails, and a new session has
been created instead.
Raises :class:`TimeoutError` if the broker does not
acknowledge the connect.
Raises :class:`ConnectError` if the broker does not accept the
connect request.
>>> await client.start()
Trying to resume a session.
Expand Down Expand Up @@ -377,6 +379,12 @@ def disconnect(self):
async def subscribe(self, topic):
"""Subscribe to given topic with QoS 0.
Raises :class:`TimeoutError` if the broker does not
acknowledge the subscribe request.
Raises :class:`SubscribeError` if the broker does not accept
the subscribe request.
>>> await client.subscribe('/my/topic')
>>> await client.messages.get()
('/my/topic', b'my-message')
Expand All @@ -400,6 +408,12 @@ async def subscribe(self, topic):
async def unsubscribe(self, topic):
"""Unsubscribe from given topic.
Raises :class:`TimeoutError` if the broker does not
acknowledge the unsubscribe request.
Raises :class:`UnsubscribeError` if the broker does not accept
the unsubscribe request.
>>> await client.unsubscribe('/my/topic')
"""
Expand Down

0 comments on commit 2efd6bb

Please sign in to comment.