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
 
67
 
68
         # Remove the echoed command and prompt
68
         # Remove the echoed command and prompt
69
         answer = answer[1:-1]
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
         return answer
75
         return answer
71
 
76
 
72
     def close(self):
77
     def close(self):
167
             elif value[0] == b"disabled":
172
             elif value[0] == b"disabled":
168
                 return False
173
                 return False
169
             else:
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
                 # If unexpected text is returned, raise an exception indicating a
175
                 # If unexpected text is returned, raise an exception indicating a
174
                 # firmware error
176
                 # firmware error
175
                 raise ValueError("unknown output state")
177
                 raise ValueError("unknown output state")

Loading…
Cancel
Save