From 8ec39ca52e03a24688544b6fbcb8cd42cb825418 Mon Sep 17 00:00:00 2001 From: David Hay Date: Thu, 24 Oct 2024 17:18:41 -0600 Subject: [PATCH] Add error handling to get_focus_mode --- visca_over_ip/camera.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/visca_over_ip/camera.py b/visca_over_ip/camera.py index 8175729..793b2a9 100644 --- a/visca_over_ip/camera.py +++ b/visca_over_ip/camera.py @@ -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: @@ -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 \ No newline at end of file