From 613f5e761f3cf39275a5e3f3df34ac6160ce2ff6 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Sun, 8 Nov 2026 12:43:53 +0100 Subject: [PATCH 1/2] camera, transport: Fix enum value checks on Python < 3.12. Before Python 3.12, using "in" on an Enum class with a value that is not a member raises TypeError instead of returning False. Look the value up and catch ValueError instead. Signed-off-by: iabdalkader --- src/openmv/camera.py | 5 ++++- src/openmv/transport.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) 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..84db9b1 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 From cd7dd75bb5e7d27d3301899a4345330ff81bc7f5 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Sun, 8 Nov 2026 12:44:39 +0100 Subject: [PATCH 2/2] transport: Fix the exception raised on an unknown NAK status. An unknown status raised ValueError while building the message instead of OMVException, so the caller exited instead of resyncing. Signed-off-by: iabdalkader --- src/openmv/transport.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/openmv/transport.py b/src/openmv/transport.py index 84db9b1..4b8b505 100644 --- a/src/openmv/transport.py +++ b/src/openmv/transport.py @@ -240,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