Skip to content

Commit d92f942

Browse files
authored
Merge pull request #63 from pedrovs16/add-missing-type-annotations
Add missing type annotations
2 parents 959a606 + 03b776c commit d92f942

File tree

1 file changed

+41
-21
lines changed

1 file changed

+41
-21
lines changed

adafruit_irremote.py

+41-21
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5+
# pylint: disable=missing-module-docstring
6+
from __future__ import annotations
7+
8+
import array
9+
from collections import namedtuple
10+
import time
11+
12+
try:
13+
from typing import List, NamedTuple, Optional, Tuple
14+
from pulseio import PulseOut
15+
except ImportError:
16+
pass
17+
518
"""
619
`adafruit_irremote`
720
====================================================
@@ -50,9 +63,6 @@
5063
https://github.com/adafruit/circuitpython/releases
5164
5265
"""
53-
import array
54-
from collections import namedtuple
55-
import time
5666

5767
__version__ = "0.0.0+auto.0"
5868
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_IRRemote.git"
@@ -66,7 +76,7 @@ class IRNECRepeatException(Exception):
6676
"""Exception when a NEC repeat is decoded"""
6777

6878

69-
def bin_data(pulses):
79+
def bin_data(pulses: List) -> List[List]:
7080
"""Compute bins of pulse lengths where pulses are +-25% of the average.
7181
7282
:param list pulses: Input pulse lengths
@@ -89,7 +99,7 @@ def bin_data(pulses):
8999
return bins
90100

91101

92-
def decode_bits(pulses):
102+
def decode_bits(pulses: List) -> NamedTuple:
93103
"""Decode the pulses into bits."""
94104
# pylint: disable=too-many-branches,too-many-statements
95105

@@ -211,12 +221,12 @@ class NonblockingGenericDecode:
211221
... ...
212222
"""
213223

214-
def __init__(self, pulses, max_pulse=10_000):
224+
def __init__(self, pulses: List, max_pulse: int = 10_000) -> None:
215225
self.pulses = pulses # PulseIn
216226
self.max_pulse = max_pulse
217227
self._unparsed_pulses = [] # internal buffer of partial messages
218228

219-
def read(self):
229+
def read(self) -> None:
220230
"""
221231
Consume all pulses from PulseIn. Yield decoded messages, if any.
222232
@@ -254,11 +264,11 @@ class GenericDecode:
254264
# this here for back-compat, hence we disable pylint for that specific
255265
# complaint.
256266

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

261-
def decode_bits(self, pulses): # pylint: disable=no-self-use
271+
def decode_bits(self, pulses: List) -> Tuple: # pylint: disable=no-self-use
262272
"Wraps the top-level function decode_bits for backward-compatibility."
263273
try:
264274
result = decode_bits(pulses)
@@ -268,9 +278,9 @@ def decode_bits(self, pulses): # pylint: disable=no-self-use
268278
raise IRNECRepeatException()
269279
return result.code
270280

271-
def _read_pulses_non_blocking(
272-
self, input_pulses, max_pulse=10000, pulse_window=0.10
273-
): # pylint: disable=no-self-use
281+
def _read_pulses_non_blocking( # pylint: disable=no-self-use
282+
self, input_pulses: List, max_pulse: int = 10000, pulse_window: float = 0.10
283+
) -> Optional[List]:
274284
"""Read out a burst of pulses without blocking until pulses stop for a specified
275285
period (pulse_window), pruning pulses after a pulse longer than ``max_pulse``.
276286
@@ -304,13 +314,13 @@ def _read_pulses_non_blocking(
304314

305315
def read_pulses(
306316
self,
307-
input_pulses,
317+
input_pulses: list,
308318
*,
309-
max_pulse=10000,
310-
blocking=True,
311-
pulse_window=0.10,
312-
blocking_delay=0.10,
313-
):
319+
max_pulse: int = 10000,
320+
blocking: bool = True,
321+
pulse_window: float = 0.10,
322+
blocking_delay: float = 0.10,
323+
) -> Optional[List]:
314324
"""Read out a burst of pulses until pulses stop for a specified
315325
period (pulse_window), pruning pulses after a pulse longer than ``max_pulse``.
316326
@@ -342,20 +352,30 @@ class GenericTransmit:
342352
:param bool debug: Enable debug output, default False
343353
"""
344354

345-
def __init__(self, header, one, zero, trail, *, debug=False):
355+
def __init__(
356+
self, header: int, one: int, zero: int, trail: int, *, debug: bool = False
357+
) -> None:
346358
self.header = header
347359
self.one = one
348360
self.zero = zero
349361
self.trail = trail
350362
self.debug = debug
351363

352-
def transmit(self, pulseout, data, *, repeat=0, delay=0, nbits=None):
364+
def transmit(
365+
self,
366+
pulseout: PulseOut,
367+
data: bytearray,
368+
*,
369+
repeat: int = 0,
370+
delay: float = 0.0,
371+
nbits: Optional[int] = None,
372+
) -> None:
353373
"""Transmit the ``data`` using the ``pulseout``.
354374
355375
:param pulseio.PulseOut pulseout: PulseOut to transmit on
356376
:param bytearray data: Data to transmit
357377
:param int repeat: Number of additional retransmissions of the data, default 0
358-
:param float delay: Delay between any retransmissions, default 0
378+
:param float delay: Delay between any retransmissions, default 0.0
359379
:param int nbits: Optional number of bits to send,
360380
useful to send fewer bits than in the data bytes
361381
"""

0 commit comments

Comments
 (0)