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