瀏覽代碼

Make it obvious when output is unsupported

Now when the `output` command is unsupported by the Sink, the library
raises a different exception than if unknown text is printed.  This
allows feature testing, which is great.
Clara Hobbs 7 年之前
父節點
當前提交
6d8e976402
共有 1 個檔案被更改,包括 5 行新增2 行删除
  1. 5
    2
      pdbuddy/__init__.py

+ 5
- 2
pdbuddy/__init__.py 查看文件

@@ -152,8 +152,8 @@ class Sink:
152 152
     def output(self, state=None):
153 153
         """Gets or sets the state of a Sink's output
154 154
 
155
-        If an invalid output is read, raises ValueError.  This may indicate
156
-        that the firmware does not support the ``output`` command.
155
+        Raises KeyError if the ``output`` command is not available on the Sink.
156
+        Raises ValueError if an invalid output is read.
157 157
 
158 158
         :param state: optional value of the output to set
159 159
 
@@ -167,6 +167,9 @@ class Sink:
167 167
             elif value[0] == b"disabled":
168 168
                 return False
169 169
             else:
170
+                # If the command is unknown to the Sink, raise a KeyError
171
+                if value[0] == b"output ?":
172
+                    raise KeyError("command not found")
170 173
                 # If unexpected text is returned, raise an exception indicating a
171 174
                 # firmware error
172 175
                 raise ValueError("unknown output state")

Loading…
取消
儲存