Przeglądaj źródła

Added Sink.output method

Sink.output provides a Pythonic interface to the PD Buddy Sink's output
command.
Clara Hobbs 7 lat temu
rodzic
commit
e40e298599
1 zmienionych plików z 29 dodań i 0 usunięć
  1. 29
    0
      pdbuddy/__init__.py

+ 29
- 0
pdbuddy/__init__.py Wyświetl plik

@@ -149,6 +149,35 @@ class Sink:
149 149
         """Blinks the LED quickly"""
150 150
         self.send_command("identify")
151 151
 
152
+    def output(self, state=None):
153
+        """Gets or sets the state of a Sink's output
154
+
155
+        If an invalid output is read, raises ValueError.  This may indicate
156
+        that the firmware does not support the ``output`` command.
157
+
158
+        :param state: optional value of the output to set
159
+
160
+        :returns: the output state if state is None, None otherwise
161
+        """
162
+        # With no parameter, return the output state
163
+        if state is None:
164
+            value = self.send_command("output")
165
+            if value[0] == b"enabled":
166
+                return True
167
+            elif value[0] == b"disabled":
168
+                return False
169
+            else:
170
+                # If unexpected text is returned, raise an exception indicating a
171
+                # firmware error
172
+                raise ValueError("unknown output state")
173
+
174
+        # With a parameter, set the output state
175
+        if state:
176
+            self.send_command("output enable")
177
+        else:
178
+            self.send_command("output disable")
179
+
180
+
152 181
     def set_tmpcfg(self, sc):
153 182
         """Writes a SinkConfig object to the device's configuration buffer
154 183
         

Ładowanie…
Anuluj
Zapisz