kopia lustrzana https://github.com/Yakifo/amqtt
lint fixing. and make sure the client is loading the correct default file
rodzic
a3de71930c
commit
bb9c92537f
|
@ -1,14 +1,14 @@
|
|||
import asyncio
|
||||
import copy
|
||||
from asyncio import CancelledError, futures
|
||||
from collections import deque
|
||||
from collections.abc import Generator
|
||||
import copy
|
||||
from enum import Enum
|
||||
from functools import partial
|
||||
import logging
|
||||
from pathlib import Path
|
||||
import re
|
||||
import ssl
|
||||
from pathlib import Path
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from transitions import Machine, MachineError
|
||||
|
|
|
@ -5,8 +5,8 @@ import contextlib
|
|||
import copy
|
||||
from functools import wraps
|
||||
import logging
|
||||
import ssl
|
||||
from pathlib import Path
|
||||
import ssl
|
||||
from typing import TYPE_CHECKING, Any, cast
|
||||
from urllib.parse import urlparse, urlunparse
|
||||
|
||||
|
@ -30,7 +30,8 @@ from amqtt.utils import gen_client_id, read_yaml_config
|
|||
if TYPE_CHECKING:
|
||||
from websockets.asyncio.client import ClientConnection
|
||||
|
||||
_defaults: dict[str, Any] | None = read_yaml_config(Path(__file__).parent / "scripts/default_broker.yaml")
|
||||
_defaults: dict[str, Any] | None = read_yaml_config(Path(__file__).parent / "scripts/default_client.yaml")
|
||||
|
||||
|
||||
class ClientContext(BaseContext):
|
||||
"""ClientContext is used as the context passed to plugins interacting with the client.
|
||||
|
@ -79,10 +80,12 @@ def mqtt_connected(func: _F) -> _F:
|
|||
class MQTTClient:
|
||||
"""MQTT client implementation.
|
||||
|
||||
MQTTClient instances provides API for connecting to a broker and send/receive messages using the MQTT protocol.
|
||||
MQTTClient instances provides API for connecting to a broker and send/receive
|
||||
messages using the MQTT protocol.
|
||||
|
||||
Args:
|
||||
client_id: MQTT client ID to use when connecting to the broker. If none, it will be generated randomly by `amqtt.utils.gen_client_id`
|
||||
client_id: MQTT client ID to use when connecting to the broker. If none,
|
||||
it will be generated randomly by `amqtt.utils.gen_client_id`
|
||||
config: dictionary of configuration options (see [client configuration](client_config.md)).
|
||||
|
||||
"""
|
||||
|
@ -125,18 +128,22 @@ class MQTTClient:
|
|||
message is sent with the requested information.
|
||||
|
||||
Args:
|
||||
uri: Broker URI connection, conforming to [MQTT URI scheme](https://github.com/mqtt/mqtt.github.io/wiki/URI-Scheme). default, ``uri`` config attribute.
|
||||
uri: Broker URI connection, conforming to
|
||||
[MQTT URI scheme](https://github.com/mqtt/mqtt.github.io/wiki/URI-Scheme). default,
|
||||
will be taken from the ``uri`` config attribute.
|
||||
cleansession: MQTT CONNECT clean session flag
|
||||
cafile: server certificate authority file (optional, used for secured connection)
|
||||
capath: server certificate authority path (optional, used for secured connection)
|
||||
cadata: server certificate authority data (optional, used for secured connection)
|
||||
additional_headers: a dictionary with additional http headers that should be sent on the initial connection (optional, used only with websocket connections)
|
||||
additional_headers: a dictionary with additional http headers that should be sent on the
|
||||
initial connection (optional, used only with websocket connections)
|
||||
|
||||
Returns:
|
||||
[CONNACK](http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718033)'s return code
|
||||
|
||||
Raises:
|
||||
amqtt.client.ConnectException: if connection fails
|
||||
|
||||
"""
|
||||
additional_headers = additional_headers if additional_headers is not None else {}
|
||||
self.session = self._init_session(uri, cleansession, cafile, capath, cadata)
|
||||
|
@ -201,6 +208,7 @@ class MQTTClient:
|
|||
|
||||
Raises:
|
||||
amqtt.client.ConnectException: if re-connection fails after max retries.
|
||||
|
||||
"""
|
||||
if self.session and self.session.transitions.is_connected():
|
||||
self.logger.warning("Client already connected")
|
||||
|
@ -271,7 +279,8 @@ class MQTTClient:
|
|||
Args:
|
||||
topic: topic name to which message data is published
|
||||
message: payload message (as bytes) to send.
|
||||
qos: requested publish quality of service : QOS_0, QOS_1 or QOS_2. Defaults to `default_qos` config parameter or QOS_0.
|
||||
qos: requested publish quality of service : QOS_0, QOS_1 or QOS_2. Defaults to `default_qos`
|
||||
config parameter or QOS_0.
|
||||
retain: retain flag. Defaults to ``default_retain`` config parameter or False.
|
||||
ack_timeout: duration to wait for connection acknowledgment from broker.
|
||||
|
||||
|
@ -347,6 +356,7 @@ class MQTTClient:
|
|||
```
|
||||
["$SYS/broker/uptime", "$SYS/broker/load/#"]
|
||||
```
|
||||
|
||||
"""
|
||||
if self._handler and self.session:
|
||||
await self._handler.mqtt_unsubscribe(topics, self.session.next_packet_id)
|
||||
|
@ -365,6 +375,7 @@ class MQTTClient:
|
|||
|
||||
Raises:
|
||||
asyncio.TimeoutError: if timeout occurs before a message is delivered
|
||||
|
||||
"""
|
||||
if self._handler is None:
|
||||
msg = "Handler is not initialized."
|
||||
|
|
|
@ -18,8 +18,7 @@ class BaseAuthPlugin:
|
|||
self.context.logger.warning("'auth' section not found in context configuration")
|
||||
|
||||
async def authenticate(self, *args: None, **kwargs: Session) -> bool | None:
|
||||
"""
|
||||
Logic for session authentication.
|
||||
"""Logic for session authentication.
|
||||
|
||||
Args:
|
||||
*args: positional arguments (not used)
|
||||
|
@ -31,6 +30,7 @@ class BaseAuthPlugin:
|
|||
Returns:
|
||||
- `True` if user is authentication succeed, `False` if user authentication fails
|
||||
- `None` if authentication can't be achieved (then plugin result is then ignored)
|
||||
|
||||
"""
|
||||
if not self.auth_config:
|
||||
# auth config section not found
|
||||
|
|
|
@ -14,8 +14,7 @@ class BaseTopicPlugin:
|
|||
self.context.logger.warning("'topic-check' section not found in context configuration")
|
||||
|
||||
async def topic_filtering(self, *args: Any, **kwargs: Any) -> bool:
|
||||
"""
|
||||
Logic for filtering out topics.
|
||||
"""Logic for filtering out topics.
|
||||
|
||||
Args:
|
||||
*args: positional arguments (not used)
|
||||
|
@ -29,7 +28,8 @@ class BaseTopicPlugin:
|
|||
|
||||
Returns:
|
||||
bool: `True` if topic is allowed, `False` otherwise
|
||||
"""
|
||||
|
||||
"""
|
||||
if not self.topic_config:
|
||||
# auth config section not found
|
||||
self.context.logger.warning("'auth' section not found in context configuration")
|
||||
|
|
|
@ -169,7 +169,7 @@ max-returns = 10
|
|||
|
||||
# ----------------------------------- PYTEST -----------------------------------
|
||||
[tool.pytest.ini_options]
|
||||
addopts = ["--cov=amqtt", "--cov-report=term-missing", "--cov-report=xml"]
|
||||
addopts = ["--cov=amqtt", "--cov-report=term-missing", "--cov-report=html"]
|
||||
testpaths = ["tests"]
|
||||
asyncio_mode = "auto"
|
||||
timeout = 10
|
||||
|
|
Ładowanie…
Reference in New Issue