diff --git a/src/openmv/camera.py b/src/openmv/camera.py index 97e7114..979ec2a 100644 --- a/src/openmv/camera.py +++ b/src/openmv/camera.py @@ -104,7 +104,10 @@ def _handle_event(self, channel_id, event): """Handle events from the device""" if channel_id == 0: # System events - event_name = EventType(event).name if event in EventType else f"0x{event:04X}" + try: + event_name = EventType(event).name + except ValueError: + event_name = f"0x{event:04X}" logging.info(f"🔔 System Event: channel=system, event={event_name}") # Handle system events diff --git a/src/openmv/transport.py b/src/openmv/transport.py index 6f72202..4b8b505 100644 --- a/src/openmv/transport.py +++ b/src/openmv/transport.py @@ -115,7 +115,10 @@ def log(self, seq=None, ch=None, opcode=None, flags=None, length=None, direction flags = packet['flags'] length = packet['length'] - opcode_str = Opcode(opcode).name if opcode in Opcode else f"0x{opcode:02X}" + try: + opcode_str = Opcode(opcode).name + except ValueError: + opcode_str = f"0x{opcode:02X}" flags_str = self._format_flags(flags) # Add emoji based on packet type and direction @@ -237,7 +240,11 @@ def recv_packet(self, poll_events=False): elif status == Status.TIMEOUT: raise TimeoutException("") elif status != Status.BUSY: - raise OMVException(f"Command failed with status: {Status(status).name}") + try: + status_str = Status(status).name + except ValueError: + status_str = f"0x{status:04X}" + raise OMVException(f"Command failed with status: {status_str}") return False # Either last fragment or non-fragmented packet