Skip to content
Snippets Groups Projects
Commit 08786262 authored by Matthias Stefan Bodenbenner's avatar Matthias Stefan Bodenbenner
Browse files

2.6.0 - improved interaction with instances

parent 39680034
No related branches found
No related tags found
No related merge requests found
Pipeline #345714 passed
......@@ -115,4 +115,4 @@ venv.bak/
logs/
private_testing/
private_test/
# WZL-MQTT
Current stable version: 2.5.4
Current stable version: 2.6.0
## Documentation
......@@ -90,6 +90,10 @@ the European Union’s Horizon 2020 research and innovation programme and the EM
## Changelog
**2.6.0** - 2024-01-10
- added the classmethod "client_names()" to client to retrieve the name of all instances
- the classmethod "get(username)" of the client raises the "ChildNotFoundError" if there is no instance having the specified username
**2.5.4** - 2023-04-18
- fixed usage of a randomized client_id, so that the same credentials can be used for multiple clients in parallel
......
......@@ -4,7 +4,7 @@ with open("PyPI-README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()
setup(name='wzl-mqtt',
version='2.5.4',
version='2.6.0',
url='https://git-ce.rwth-aachen.de/wzl-mq-public/iot/mqtt/',
project_urls={
"Bug Tracker": "https://git-ce.rwth-aachen.de/wzl-mq-public/iot/mqtt/-/issues",
......
......@@ -3,11 +3,11 @@ import sys
import traceback
import uuid
import warnings
from typing import Callable, Union
from typing import Callable, Union, List
import paho.mqtt.client as mqtt
from .exceptions import ConnectionError
from .exceptions import ConnectionError, ClientNotFoundError
from .exceptions import PublishError
from .exceptions import SubscriptionError
from .logger import Logger
......@@ -69,8 +69,23 @@ class MQTTClient:
Returns: The client identified by the given key.
Raises:
ChildNotFoundError: If no client with the given username could be found.
"""
try:
return cls.instances[username]
except KeyError:
raise ClientNotFoundError(f'There is no client with name "{username}".')
@classmethod
def client_names(cls) -> List[str]:
"""Returns al list of the usernames of all clients.
Returns: List of the usernames of all clients.
"""
return [key for key in cls.instances]
@property
def connected(self) -> bool:
......
......@@ -21,3 +21,8 @@ class CallbackError(MQTTException):
class PublishError(MQTTException):
def __init__(self, *args, **kwargs):
MQTTException.__init__(self, *args, **kwargs)
class ClientNotFoundError(MQTTException):
def __init__(self, *args, **kwargs):
MQTTException.__init__(self, *args, **kwargs)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment