Browse Source

rST docstrings

Clara Hobbs 7 years ago
parent
commit
64ed72e4e0
1 changed files with 19 additions and 24 deletions
  1. 19
    24
      pdbuddy/__init__.py

+ 19
- 24
pdbuddy/__init__.py View File

12
     pid = 0x0001
12
     pid = 0x0001
13
 
13
 
14
     def __init__(self, sp):
14
     def __init__(self, sp):
15
-        """Open the serial port to communicate with the PD Buddy Sink
15
+        """Open a serial port to communicate with the PD Buddy Sink
16
         
16
         
17
-        Parameters:
18
-            sp: A serial.tools.list_ports.ListPortInfo object
17
+        :param sp: the serial port of the device
18
+        :type sp: str or `serial.tools.list_ports.ListPortInfo`
19
         """
19
         """
20
         self.port = serial.Serial(sp.device, baudrate=115200)
20
         self.port = serial.Serial(sp.device, baudrate=115200)
21
 
21
 
22
     def send_command(self, cmd):
22
     def send_command(self, cmd):
23
         """Send a command to the PD Buddy Sink, returning the result
23
         """Send a command to the PD Buddy Sink, returning the result
24
         
24
         
25
-        Parameters:
26
-            cmd: A string containing the text to send to the Sink
25
+        :param cmd: the text to send to the Sink
26
+        :type sp: str
27
         
27
         
28
-        Returns:
29
-            A list of zero or more bytes objects, each being one line printed
30
-            as a response to the command.
28
+        :returns: a list of zero or more bytes objects, each being one line
29
+            printed as a response to the command.
31
         """
30
         """
32
         # Send the command
31
         # Send the command
33
         self.port.write(bytes(cmd, "utf-8") + b"\r\n")
32
         self.port.write(bytes(cmd, "utf-8") + b"\r\n")
62
     def load(self):
61
     def load(self):
63
         """Loads the current configuration from flash into the buffer
62
         """Loads the current configuration from flash into the buffer
64
         
63
         
65
-        Raises KeyError if there is no configuration in flash.
64
+        :raises: KeyError
66
         """
65
         """
67
         text = self.send_command("load")
66
         text = self.send_command("load")
68
         if len(text) > 0 and text[0].startswith(b"No configuration"):
67
         if len(text) > 0 and text[0].startswith(b"No configuration"):
71
     def get_cfg(self, index=None):
70
     def get_cfg(self, index=None):
72
         """Reads configuration from flash
71
         """Reads configuration from flash
73
          
72
          
74
-        Parameters:
75
-            index: Optional index of configuration object in flash to read
73
+        :param index: optional index of configuration object in flash to read
76
 
74
 
77
-        Returns:
78
-            A SinkConfig object
75
+        :returns: a `SinkConfig` object
79
         """
76
         """
80
         if index is None:
77
         if index is None:
81
             cfg = self.send_command("get_cfg")
78
             cfg = self.send_command("get_cfg")
87
     def get_tmpcfg(self):
84
     def get_tmpcfg(self):
88
         """Reads the contents of the configuration buffer
85
         """Reads the contents of the configuration buffer
89
 
86
 
90
-        Returns:
91
-            A SinkConfig object
87
+        :returns: a `SinkConfig` object
92
         """
88
         """
93
         cfg = self.send_command("get_tmpcfg")
89
         cfg = self.send_command("get_tmpcfg")
94
 
90
 
118
         """Writes a SinkConfig object to the device's configuration buffer
114
         """Writes a SinkConfig object to the device's configuration buffer
119
         
115
         
120
         Note: the value of the status field is ignored; it will always be
116
         Note: the value of the status field is ignored; it will always be
121
-        SinkStatus.VALID.
117
+        `SinkStatus.VALID`.
122
         """
118
         """
123
         # Set flags
119
         # Set flags
124
         self.clear_flags()
120
         self.clear_flags()
135
     def get_devices(cls):
131
     def get_devices(cls):
136
         """Get an iterable of PD Buddy Sink devices
132
         """Get an iterable of PD Buddy Sink devices
137
         
133
         
138
-        Returns an iterable of serial.tools.list_ports.ListPortInfo objects.
134
+        :returns: an iterable of `serial.tools.list_ports.ListPortInfo` objects
139
         """
135
         """
140
         return serial.tools.list_ports.grep("{:04X}:{:04X}".format(cls.vid,
136
         return serial.tools.list_ports.grep("{:04X}:{:04X}".format(cls.vid,
141
             cls.pid))
137
             cls.pid))
147
     def __init__(self, status=None, flags=None, v=None, i=None):
143
     def __init__(self, status=None, flags=None, v=None, i=None):
148
         """Create a SinkConfig object
144
         """Create a SinkConfig object
149
         
145
         
150
-        Parameters:
151
-            status: A SinkStatus value
152
-            flags: Zero or more SinkFlags values
153
-            v: Voltage in millivolts
154
-            i: Current in milliamperes
146
+        :param status: A `SinkStatus` value
147
+        :param flags: Zero or more `SinkFlags` values
148
+        :param v: Voltage in millivolts
149
+        :param i: Current in milliamperes
155
         """
150
         """
156
         self.status = status
151
         self.status = status
157
         self.flags = flags
152
         self.flags = flags
240
     def from_text(cls, text):
235
     def from_text(cls, text):
241
         """Creates a SinkConfig from text returned by Sink.send_command
236
         """Creates a SinkConfig from text returned by Sink.send_command
242
         
237
         
243
-        Returns a new SinkConfig object.
238
+        :returns: a new `SinkConfig` object.
244
 
239
 
245
-        Raises IndexError if the configuration reads "Invalid index".
240
+        :raises: IndexError
246
         """
241
         """
247
         # Assume the parameters will all be None
242
         # Assume the parameters will all be None
248
         status = None
243
         status = None

Loading…
Cancel
Save