From ed30ca9743c5e56183c8f891f6f677899e1f9636 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 25 Apr 2023 16:29:36 -0400 Subject: [PATCH] Handle FailedToDecode exception internally --- adafruit_irremote.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/adafruit_irremote.py b/adafruit_irremote.py index 6d234ee..f90354c 100644 --- a/adafruit_irremote.py +++ b/adafruit_irremote.py @@ -201,7 +201,7 @@ class NonblockingGenericDecode: >>> pulses = PulseIn(...) >>> decoder = NonblockingGenericDecoder(pulses) >>> for message in decoder.read(): - ... if isinstace(message, IRMessage): + ... if isinstance(message, IRMessage): ... message.code # TA-DA! Do something with this in your application. ... else: ... # message is either NECRepeatIRMessage or @@ -260,11 +260,12 @@ def bin_data(self, pulses): # pylint: disable=no-self-use def decode_bits(self, pulses): # pylint: disable=no-self-use "Wraps the top-level function decode_bits for backward-compatibility." - result = decode_bits(pulses) + try: + result = decode_bits(pulses) + except FailedToDecode as err: + raise IRDecodeException from err if isinstance(result, NECRepeatIRMessage): raise IRNECRepeatException() - if isinstance(result, UnparseableIRMessage): - raise IRDecodeException("10 pulses minimum") return result.code def _read_pulses_non_blocking(