54
54
from collections import namedtuple
55
55
import time
56
56
57
+ try :
58
+ from typing import List , NamedTuple , Optional , Tuple
59
+ from pulseio import PulseOut
60
+ except ImportError :
61
+ pass
62
+
57
63
__version__ = "0.0.0+auto.0"
58
64
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_IRRemote.git"
59
65
@@ -66,7 +72,7 @@ class IRNECRepeatException(Exception):
66
72
"""Exception when a NEC repeat is decoded"""
67
73
68
74
69
- def bin_data (pulses ) :
75
+ def bin_data (pulses : List ) -> List [ List ] :
70
76
"""Compute bins of pulse lengths where pulses are +-25% of the average.
71
77
72
78
:param list pulses: Input pulse lengths
@@ -89,7 +95,7 @@ def bin_data(pulses):
89
95
return bins
90
96
91
97
92
- def decode_bits (pulses ) :
98
+ def decode_bits (pulses : List ) -> NamedTuple :
93
99
"""Decode the pulses into bits."""
94
100
# pylint: disable=too-many-branches,too-many-statements
95
101
@@ -211,12 +217,12 @@ class NonblockingGenericDecode:
211
217
... ...
212
218
"""
213
219
214
- def __init__ (self , pulses , max_pulse = 10_000 ):
220
+ def __init__ (self , pulses : List , max_pulse : int = 10_000 ) -> None :
215
221
self .pulses = pulses # PulseIn
216
222
self .max_pulse = max_pulse
217
223
self ._unparsed_pulses = [] # internal buffer of partial messages
218
224
219
- def read (self ):
225
+ def read (self ) -> None :
220
226
"""
221
227
Consume all pulses from PulseIn. Yield decoded messages, if any.
222
228
@@ -254,11 +260,11 @@ class GenericDecode:
254
260
# this here for back-compat, hence we disable pylint for that specific
255
261
# complaint.
256
262
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
258
264
"Wraps the top-level function bin_data for backward-compatibility."
259
265
return bin_data (pulses )
260
266
261
- def decode_bits (self , pulses ) : # pylint: disable=no-self-use
267
+ def decode_bits (self , pulses : List ) -> Tuple : # pylint: disable=no-self-use
262
268
"Wraps the top-level function decode_bits for backward-compatibility."
263
269
result = decode_bits (pulses )
264
270
if isinstance (result , NECRepeatIRMessage ):
@@ -267,9 +273,9 @@ def decode_bits(self, pulses): # pylint: disable=no-self-use
267
273
raise IRDecodeException ("10 pulses minimum" )
268
274
return result .code
269
275
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 ]:
273
279
"""Read out a burst of pulses without blocking until pulses stop for a specified
274
280
period (pulse_window), pruning pulses after a pulse longer than ``max_pulse``.
275
281
@@ -303,13 +309,13 @@ def _read_pulses_non_blocking(
303
309
304
310
def read_pulses (
305
311
self ,
306
- input_pulses ,
312
+ input_pulses : list ,
307
313
* ,
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 ] :
313
319
"""Read out a burst of pulses until pulses stop for a specified
314
320
period (pulse_window), pruning pulses after a pulse longer than ``max_pulse``.
315
321
@@ -341,14 +347,24 @@ class GenericTransmit:
341
347
:param bool debug: Enable debug output, default False
342
348
"""
343
349
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 :
345
353
self .header = header
346
354
self .one = one
347
355
self .zero = zero
348
356
self .trail = trail
349
357
self .debug = debug
350
358
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 :
352
368
"""Transmit the ``data`` using the ``pulseout``.
353
369
354
370
:param pulseio.PulseOut pulseout: PulseOut to transmit on
0 commit comments