From d7914740ff6a74120d06374f94a94659b34e8174 Mon Sep 17 00:00:00 2001 From: benjaminwp18 <90342856+benjaminwp18@users.noreply.github.com> Date: Thu, 28 Mar 2024 12:05:50 -0400 Subject: [PATCH] more pep257 --- mqtt_ros_bridge/bridge_node.py | 36 +++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/mqtt_ros_bridge/bridge_node.py b/mqtt_ros_bridge/bridge_node.py index 426ac0d..c334030 100644 --- a/mqtt_ros_bridge/bridge_node.py +++ b/mqtt_ros_bridge/bridge_node.py @@ -13,7 +13,8 @@ @dataclass class TopicInfo(): - """Metadata about a single topic""" + """Metadata about a single topic.""" + name: str publish_on_ros: bool @@ -25,7 +26,7 @@ class TopicInfo(): class BridgeNode(Node): - """Node to bridge MQTT and ROS""" + """Node to bridge MQTT and ROS.""" def __init__(self) -> None: super().__init__('mqtt_bridge_node') @@ -53,14 +54,14 @@ def __init__(self) -> None: self.mqtt_client.on_message = self.mqtt_msg_received def make_ros_receiver(self, topic: str): - """ - Create a callback function for a ROS subscription which re-publishes - messages on the same topic in MQTT. + """Create a callback function which re-publishes messages on the same topic in MQTT. - Args: - topic (str): the topic that the callback will publish on - """ + Parameters + ---------- + topic : str + the topic that the callback will publish on + """ def callback(msg: String): self.get_logger().info(f"ROS RECEIVED: Topic: '{topic}' Payload: '{msg}'") self.mqtt_client.publish(topic, msg.data) @@ -68,15 +69,18 @@ def callback(msg: String): return callback def mqtt_msg_received(self, _client: MQTT.Client, _userdata: Any, mqtt_msg: MQTT.MQTTMessage): - """ - Re-publish messages from MQTT on the same topic in ROS. + """Re-publish messages from MQTT on the same topic in ROS. - Args: - _client (Client): unused; the MQTT client which received this message - _userdata (Any): unused; the private user data as set for the client - mqtt_msg (MQTTMessage): the message received over MQTT - """ + Parameters + ---------- + _client : MQTT.Client + unused; the MQTT client which received this message + _userdata : Any + unused; the private user data as set for the client + mqtt_msg : MQTT.MQTTMessage + the message received over MQTT + """ self.get_logger().info( f"MQTT RECEIVED: Topic: '{mqtt_msg.topic}' Payload: '{mqtt_msg.payload!r}'") @@ -86,7 +90,7 @@ def mqtt_msg_received(self, _client: MQTT.Client, _userdata: Any, mqtt_msg: MQTT def main(args=None): - """Main entrypoint for ROS executable""" + """Run bridge node; used in ROS executable.""" rclpy.init(args=args)