Browse Source

Check for invalid commands in Sink.send_command

Any command sent with send_command could be invalid.  It makes sense for
that method to throw an exception if the command isn't recognized so I
don't have to duplicate that effort in the methods for all commands
introduced after firmware version 1.0.  This commit moves the command
validity checking to Sink.send_command.
Clara Hobbs 6 years ago
parent
commit
a4d94131d6
1 changed files with 5 additions and 3 deletions
  1. 5
    3
      pdbuddy/__init__.py

+ 5
- 3
pdbuddy/__init__.py View File

@@ -67,6 +67,11 @@ class Sink:
67 67
 
68 68
         # Remove the echoed command and prompt
69 69
         answer = answer[1:-1]
70
+
71
+        # Raise an exception if the command wasn't recognized
72
+        if len(answer) and answer[0] == cmd.strip().split()[0] + b" ?":
73
+            raise KeyError("command not found")
74
+
70 75
         return answer
71 76
 
72 77
     def close(self):
@@ -167,9 +172,6 @@ class Sink:
167 172
             elif value[0] == b"disabled":
168 173
                 return False
169 174
             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")
173 175
                 # If unexpected text is returned, raise an exception indicating a
174 176
                 # firmware error
175 177
                 raise ValueError("unknown output state")

Loading…
Cancel
Save