Skip to content

Commit

Permalink
Merge pull request #64 from dhalbert/handle-failedtodecode
Browse files Browse the repository at this point in the history
Handle FailedToDecode exception internally
  • Loading branch information
dhalbert authored Apr 25, 2023
2 parents 340c62e + ed30ca9 commit 365618e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions adafruit_irremote.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 365618e

Please sign in to comment.