Skip to content

Commit

Permalink
Merge pull request #30 from misterhay/update-get_focus_mode-error-handle
Browse files Browse the repository at this point in the history
Add error handling to get_focus_mode
  • Loading branch information
misterhay authored Oct 27, 2024
2 parents cbbd311 + 8ec39ca commit 03542f6
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions visca_over_ip/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def _receive_response(self) -> Optional[bytes]:
"""Attempts to receive the response of the most recent command.
Sometimes we don't get the response because this is UDP.
In that case we just increment num_missed_responses and move on.
:raises ViscaException: if the response if an error and not an acknowledge or completion
:raises ViscaException: if the response is an error and not an acknowledge or completion
"""
while True:
try:
Expand Down Expand Up @@ -639,9 +639,16 @@ def get_zoom_position(self) -> int:
return self._zero_padded_bytes_to_int(response[1:], signed=False)

def get_focus_mode(self) -> str:
""":return: either 'auto' or 'manual'"""
""":return: either 'auto' or 'manual'
:raises ViscaException: if the response is not 2 or 3
"""
modes = {2: 'auto', 3: 'manual'}
response = self._send_command('04 38', query=True)
return modes[response[-1]]
try:
mode = modes[response[-1]]
except KeyError:
mode = 'unknown'
raise ViscaException(response)
return mode

# other inquiry commands

0 comments on commit 03542f6

Please sign in to comment.