2
2
#
3
3
# SPDX-License-Identifier: MIT
4
4
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
+
5
18
"""
6
19
`adafruit_irremote`
7
20
====================================================
50
63
https://github.com/adafruit/circuitpython/releases
51
64
52
65
"""
53
- import array
54
- from collections import namedtuple
55
- import time
56
66
57
67
__version__ = "0.0.0+auto.0"
58
68
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_IRRemote.git"
@@ -66,7 +76,7 @@ class IRNECRepeatException(Exception):
66
76
"""Exception when a NEC repeat is decoded"""
67
77
68
78
69
- def bin_data (pulses ) :
79
+ def bin_data (pulses : List ) -> List [ List ] :
70
80
"""Compute bins of pulse lengths where pulses are +-25% of the average.
71
81
72
82
:param list pulses: Input pulse lengths
@@ -89,7 +99,7 @@ def bin_data(pulses):
89
99
return bins
90
100
91
101
92
- def decode_bits (pulses ) :
102
+ def decode_bits (pulses : List ) -> NamedTuple :
93
103
"""Decode the pulses into bits."""
94
104
# pylint: disable=too-many-branches,too-many-statements
95
105
@@ -211,12 +221,12 @@ class NonblockingGenericDecode:
211
221
... ...
212
222
"""
213
223
214
- def __init__ (self , pulses , max_pulse = 10_000 ):
224
+ def __init__ (self , pulses : List , max_pulse : int = 10_000 ) -> None :
215
225
self .pulses = pulses # PulseIn
216
226
self .max_pulse = max_pulse
217
227
self ._unparsed_pulses = [] # internal buffer of partial messages
218
228
219
- def read (self ):
229
+ def read (self ) -> None :
220
230
"""
221
231
Consume all pulses from PulseIn. Yield decoded messages, if any.
222
232
@@ -254,11 +264,11 @@ class GenericDecode:
254
264
# this here for back-compat, hence we disable pylint for that specific
255
265
# complaint.
256
266
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
258
268
"Wraps the top-level function bin_data for backward-compatibility."
259
269
return bin_data (pulses )
260
270
261
- def decode_bits (self , pulses ) : # pylint: disable=no-self-use
271
+ def decode_bits (self , pulses : List ) -> Tuple : # pylint: disable=no-self-use
262
272
"Wraps the top-level function decode_bits for backward-compatibility."
263
273
try :
264
274
result = decode_bits (pulses )
@@ -268,9 +278,9 @@ def decode_bits(self, pulses): # pylint: disable=no-self-use
268
278
raise IRNECRepeatException ()
269
279
return result .code
270
280
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 ]:
274
284
"""Read out a burst of pulses without blocking until pulses stop for a specified
275
285
period (pulse_window), pruning pulses after a pulse longer than ``max_pulse``.
276
286
@@ -304,13 +314,13 @@ def _read_pulses_non_blocking(
304
314
305
315
def read_pulses (
306
316
self ,
307
- input_pulses ,
317
+ input_pulses : list ,
308
318
* ,
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 ] :
314
324
"""Read out a burst of pulses until pulses stop for a specified
315
325
period (pulse_window), pruning pulses after a pulse longer than ``max_pulse``.
316
326
@@ -342,20 +352,30 @@ class GenericTransmit:
342
352
:param bool debug: Enable debug output, default False
343
353
"""
344
354
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 :
346
358
self .header = header
347
359
self .one = one
348
360
self .zero = zero
349
361
self .trail = trail
350
362
self .debug = debug
351
363
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 :
353
373
"""Transmit the ``data`` using the ``pulseout``.
354
374
355
375
:param pulseio.PulseOut pulseout: PulseOut to transmit on
356
376
:param bytearray data: Data to transmit
357
377
: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
359
379
:param int nbits: Optional number of bits to send,
360
380
useful to send fewer bits than in the data bytes
361
381
"""
0 commit comments