Skip to content

Commit cc9a8fc

Browse files
author
Pedro Viana Schroeder
committed
Add missing type annotations
1 parent 340c62e commit cc9a8fc

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

adafruit_irremote.py

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@
5454
from collections import namedtuple
5555
import time
5656

57+
try:
58+
from typing import List, NamedTuple, Optional, Tuple
59+
from pulseio import PulseOut
60+
except ImportError:
61+
pass
62+
5763
__version__ = "0.0.0+auto.0"
5864
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_IRRemote.git"
5965

@@ -66,7 +72,7 @@ class IRNECRepeatException(Exception):
6672
"""Exception when a NEC repeat is decoded"""
6773

6874

69-
def bin_data(pulses):
75+
def bin_data(pulses: List) -> List[List]:
7076
"""Compute bins of pulse lengths where pulses are +-25% of the average.
7177
7278
:param list pulses: Input pulse lengths
@@ -89,7 +95,7 @@ def bin_data(pulses):
8995
return bins
9096

9197

92-
def decode_bits(pulses):
98+
def decode_bits(pulses: List) -> NamedTuple:
9399
"""Decode the pulses into bits."""
94100
# pylint: disable=too-many-branches,too-many-statements
95101

@@ -211,12 +217,12 @@ class NonblockingGenericDecode:
211217
... ...
212218
"""
213219

214-
def __init__(self, pulses, max_pulse=10_000):
220+
def __init__(self, pulses: List, max_pulse: int = 10_000) -> None:
215221
self.pulses = pulses # PulseIn
216222
self.max_pulse = max_pulse
217223
self._unparsed_pulses = [] # internal buffer of partial messages
218224

219-
def read(self):
225+
def read(self) -> None:
220226
"""
221227
Consume all pulses from PulseIn. Yield decoded messages, if any.
222228
@@ -254,11 +260,11 @@ class GenericDecode:
254260
# this here for back-compat, hence we disable pylint for that specific
255261
# complaint.
256262

257-
def bin_data(self, pulses): # pylint: disable=no-self-use
263+
def bin_data(self, pulses: List) -> List[List]: # pylint: disable=no-self-use
258264
"Wraps the top-level function bin_data for backward-compatibility."
259265
return bin_data(pulses)
260266

261-
def decode_bits(self, pulses): # pylint: disable=no-self-use
267+
def decode_bits(self, pulses: List) -> Tuple: # pylint: disable=no-self-use
262268
"Wraps the top-level function decode_bits for backward-compatibility."
263269
result = decode_bits(pulses)
264270
if isinstance(result, NECRepeatIRMessage):
@@ -267,9 +273,9 @@ def decode_bits(self, pulses): # pylint: disable=no-self-use
267273
raise IRDecodeException("10 pulses minimum")
268274
return result.code
269275

270-
def _read_pulses_non_blocking(
271-
self, input_pulses, max_pulse=10000, pulse_window=0.10
272-
): # pylint: disable=no-self-use
276+
def _read_pulses_non_blocking( # pylint: disable=no-self-use
277+
self, input_pulses: List, max_pulse: int = 10000, pulse_window: int = 0.10
278+
) -> Optional[List]:
273279
"""Read out a burst of pulses without blocking until pulses stop for a specified
274280
period (pulse_window), pruning pulses after a pulse longer than ``max_pulse``.
275281
@@ -303,13 +309,13 @@ def _read_pulses_non_blocking(
303309

304310
def read_pulses(
305311
self,
306-
input_pulses,
312+
input_pulses: list,
307313
*,
308-
max_pulse=10000,
309-
blocking=True,
310-
pulse_window=0.10,
311-
blocking_delay=0.10,
312-
):
314+
max_pulse: int = 10000,
315+
blocking: bool = True,
316+
pulse_window: bool = 0.10,
317+
blocking_delay: bool = 0.10,
318+
) -> Optional[List]:
313319
"""Read out a burst of pulses until pulses stop for a specified
314320
period (pulse_window), pruning pulses after a pulse longer than ``max_pulse``.
315321
@@ -341,14 +347,24 @@ class GenericTransmit:
341347
:param bool debug: Enable debug output, default False
342348
"""
343349

344-
def __init__(self, header, one, zero, trail, *, debug=False):
350+
def __init__(
351+
self, header: int, one: int, zero: int, trail: int, *, debug=False
352+
) -> None:
345353
self.header = header
346354
self.one = one
347355
self.zero = zero
348356
self.trail = trail
349357
self.debug = debug
350358

351-
def transmit(self, pulseout, data, *, repeat=0, delay=0, nbits=None):
359+
def transmit(
360+
self,
361+
pulseout: PulseOut,
362+
data: bytearray,
363+
*,
364+
repeat: int = 0,
365+
delay: int = 0,
366+
nbits: int = None,
367+
) -> None:
352368
"""Transmit the ``data`` using the ``pulseout``.
353369
354370
:param pulseio.PulseOut pulseout: PulseOut to transmit on

0 commit comments

Comments
 (0)