Skip to content

Commit

Permalink
Resolved pylint issues in server.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes.Hennecke committed Nov 27, 2023
1 parent f62bbfc commit cb38786
Showing 1 changed file with 41 additions and 36 deletions.
77 changes: 41 additions & 36 deletions mqtt_io/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ def __init__(
Parameters:
config (Dict[str, Any]): The configuration for the class.
loop (Optional[asyncio.AbstractEventLoop]): The event loop to use. If not provided, the default event loop will be used.
loop (Optional[asyncio.AbstractEventLoop]): The event loop to use.
If not provided, the default event loop will be used.
Returns:
None
Expand Down Expand Up @@ -212,10 +213,10 @@ def _init_mqtt_config(self) -> None:
"""
Initializes the MQTT configuration.
This function retrieves the MQTT configuration from the application's
main configuration file and performs the necessary setup tasks.
It sets the topic prefix for MQTT messages, replaces the '<ip>' placeholder
in the topic prefix with the IP address of the 'wlan0' interface,
This function retrieves the MQTT configuration from the application's
main configuration file and performs the necessary setup tasks.
It sets the topic prefix for MQTT messages, replaces the '<ip>' placeholder
in the topic prefix with the IP address of the 'wlan0' interface,
generates a client ID if not provided, and configures TLS options if enabled.
Parameters:
Expand Down Expand Up @@ -364,7 +365,7 @@ async def subscribe_callback(event: StreamDataSubscribeEvent) -> None:
)
)
)

if sub_topics:
self.mqtt_task_queue.put_nowait(
PriorityCoro(self._mqtt_subscribe(sub_topics), MQTT_SUB_PRIORITY)
Expand Down Expand Up @@ -453,17 +454,17 @@ async def publish_callback(event: DigitalInputChangedEvent) -> None:
def _init_digital_outputs(self) -> None:
"""
Initializes the digital outputs.
This function sets up the MQTT publish callback for the output event.
It creates a digital output queue on the right loop for each module.
It subscribes to outputs when MQTT is initialized.
It also fires DigitalOutputChangedEvents for the initial values of
outputs if required, and reads and publishes the actual pin state
This function sets up the MQTT publish callback for the output event.
It creates a digital output queue on the right loop for each module.
It subscribes to outputs when MQTT is initialized.
It also fires DigitalOutputChangedEvents for the initial values of
outputs if required, and reads and publishes the actual pin state
if no publish_initial is requested.
Parameters:
None
Returns:
None
"""
Expand All @@ -473,7 +474,8 @@ async def publish_callback(event: DigitalOutputChangedEvent) -> None:
Publishes a callback function for the given DigitalOutputChangedEvent.
Args:
event (DigitalOutputChangedEvent): The event object containing the details of the digital output change.
event (DigitalOutputChangedEvent): The event object containing the details
of the digital output change.
Returns:
None
Expand Down Expand Up @@ -636,8 +638,10 @@ async def poll_sensor(
Asynchronously polls a sensor to retrieve its value at regular intervals.
Args:
sensor_module (Optional[GenericSensor]): The sensor module to use. Defaults to the sensor_module provided during function call.
sens_conf (Optional[ConfigType]): The configuration for the sensor. Defaults to the sens_conf provided during function call.
sensor_module (Optional[GenericSensor]): The sensor module to use.
Defaults to the sensor_module provided during function call.
sens_conf (Optional[ConfigType]): The configuration for the sensor.
Defaults to the sens_conf provided during function call.
Returns:
None
Expand All @@ -655,11 +659,11 @@ async def get_sensor_value(
) -> SensorValueType:
"""
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.
sens_conf (ConfigType): The configuration for the sensor.
Returns:
SensorValueType: The value retrieved from the sensor.
"""
Expand Down Expand Up @@ -769,7 +773,8 @@ async def _mqtt_publish(self, msg: MQTTMessageSend, wait: bool = True) -> None:
Args:
msg (MQTTMessageSend): The MQTT message to publish.
wait (bool, optional): Whether to wait for MQTT connection before publishing. Defaults to True.
wait (bool, optional): Whether to wait for MQTT connection before publishing.
Defaults to True.
Raises:
RuntimeError: If the MQTT client is None.
Expand All @@ -787,21 +792,21 @@ 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 type(msg.payload) == bytes or type(msg.payload) == bytearray:
try:
payload = msg.payload.decode("utf8")
except UnicodeDecodeError:
_LOG.debug(
"Publishing MQTT message on topic %r with non-unicode payload",
msg.topic,
)
else:
_LOG.debug(
"Publishing MQTT message on topic %r: %r", msg.topic, payload
)
elif isinstance(msg.payload, bytes) or isinstance(msg.payload, bytearray):
try:
payload = msg.payload.decode("utf8")
except UnicodeDecodeError:
_LOG.debug(
"Publishing MQTT message on topic %r with non-unicode payload",
msg.topic,
)
else:
_LOG.debug(
"Publishing MQTT message on topic %r: %r", msg.topic, payload
)
else:
_LOG.debug(
f"Publishing MQTT message on topic {msg.topic}: {msg.payload}"
"Publishing MQTT message on topic %r: %r", msg.topic, payload
)

await self.mqtt.publish(msg)
Expand Down Expand Up @@ -1355,13 +1360,13 @@ async def _main_loop(self) -> None:
"""
Asynchronous main loop function.
This function is responsible for running the main event loop of the MQTT client.
It handles reconnecting to the MQTT broker if the connection is lost and
This function is responsible for running the main event loop of the MQTT client.
It handles reconnecting to the MQTT broker if the connection is lost and
manages the execution of critical tasks.
Parameters:
None
Returns:
None
"""
Expand Down

0 comments on commit cb38786

Please sign in to comment.