From 74c58253a4e9d72baf9b13e241639f320a9dee0d Mon Sep 17 00:00:00 2001 From: "Johannes.Hennecke" Date: Mon, 27 Nov 2023 14:31:42 +0100 Subject: [PATCH] Resolved pylint issues in asyncio_mqtt.py --- mqtt_io/mqtt/asyncio_mqtt.py | 18 +++++++++++------- mqtt_io/server.py | 5 +++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/mqtt_io/mqtt/asyncio_mqtt.py b/mqtt_io/mqtt/asyncio_mqtt.py index e1c3fff5..9c11b6ad 100644 --- a/mqtt_io/mqtt/asyncio_mqtt.py +++ b/mqtt_io/mqtt/asyncio_mqtt.py @@ -27,7 +27,8 @@ def _map_exception(func: Func) -> Func: """ - Creates a decorator that wraps a function and maps any raised `MqttError` exception to a `MQTTException`. + Creates a decorator that wraps a function and maps any raised `MqttError` + exception to a `MQTTException`. :param func: The function to be wrapped. :type func: Func @@ -37,7 +38,8 @@ def _map_exception(func: Func) -> Func: @wraps(func) async def inner(*args: Any, **kwargs: Any) -> Any: """ - Decorator for asynchronous functions that catches `MqttError` exceptions and raises `MQTTException` instead. + Decorator for asynchronous functions that catches `MqttError` exceptions + and raises `MQTTException` instead. Parameters: func (Callable): The function to be decorated. @@ -117,10 +119,10 @@ async def connect(self, timeout: int = 10) -> None: async def disconnect(self) -> None: """ This function is an asynchronous method that handles the disconnection of the client. - + Parameters: self: The current instance of the class. - + Returns: None """ @@ -135,8 +137,10 @@ async def subscribe(self, topics: List[Tuple[str, int]]) -> None: Subscribe to the given list of topics. Args: - topics (List[Tuple[str, int]]): A list of tuples representing the topics to subscribe to. - Each tuple should contain a string representing the topic name and an integer representing the QoS level. + topics (List[Tuple[str, int]]): A list of tuples representing the topics + to subscribe to. + Each tuple should contain a string representing the topic name and + an integer representing the QoS level. Returns: None: This function does not return anything. @@ -191,7 +195,7 @@ def _on_message( def message_queue(self) -> "asyncio.Queue[MQTTMessage]": """ Returns the message queue for receiving MQTT messages. - + :return: The message queue for receiving MQTT messages. :rtype: asyncio.Queue[MQTTMessage] """ diff --git a/mqtt_io/server.py b/mqtt_io/server.py index 3a641d0f..204fcc7c 100644 --- a/mqtt_io/server.py +++ b/mqtt_io/server.py @@ -661,7 +661,8 @@ async def get_sensor_value( A decorator that applies exponential backoff to the function `get_sensor_value`. Parameters: - sensor_module (GenericSensor): The sensor module to use for getting the sensor value. + sensor_module (GenericSensor): The sensor module to use for getting + the sensor value. sens_conf (ConfigType): The configuration for the sensor. Returns: @@ -792,7 +793,7 @@ async def _mqtt_publish(self, msg: MQTTMessageSend, wait: bool = True) -> None: if msg.payload is None: _LOG.debug("Publishing MQTT message on topic %r with no payload", msg.topic) - elif isinstance(msg.payload, bytes) or isinstance(msg.payload, bytearray): + elif isinstance(msg.payload, (bytearray, bytes)): try: payload = msg.payload.decode("utf8") except UnicodeDecodeError: