Skip to content

Commit 2a3455a

Browse files
Jeremy CeriseJeremy Cerise
Jeremy Cerise
authored and
Jeremy Cerise
committed
Based on conversation in discord, remove all non-method/function param and return types
1 parent 72fc145 commit 2a3455a

File tree

1 file changed

+36
-38
lines changed

1 file changed

+36
-38
lines changed

adafruit_rfm9x.py

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
pass
3131

3232
try:
33-
from typing import Optional, Any
33+
from typing import Optional
3434
except ImportError:
3535
pass
3636

@@ -132,7 +132,7 @@ def ticks_diff(ticks1: int, ticks2: int) -> int:
132132
"""Compute the signed difference between two ticks values
133133
assuming that they are within 2**28 ticks
134134
"""
135-
diff: int = (ticks1 - ticks2) & _TICKS_MAX
135+
diff = (ticks1 - ticks2) & _TICKS_MAX
136136
diff = ((diff + _TICKS_HALFPERIOD) & _TICKS_MAX) - _TICKS_HALFPERIOD
137137
return diff
138138

@@ -207,11 +207,11 @@ def __init__(self, address: int, *, offset: int = 0, bits: int = 1) -> None:
207207
self._offset = offset
208208

209209
def __get__(self, obj, objtype) -> int:
210-
reg_value: int = obj._read_u8(self._address)
210+
reg_value = obj._read_u8(self._address)
211211
return (reg_value & self._mask) >> self._offset
212212

213213
def __set__(self, obj, val) -> None:
214-
reg_value: int = obj._read_u8(self._address)
214+
reg_value = obj._read_u8(self._address)
215215
reg_value &= ~self._mask
216216
reg_value |= (val & 0xFF) << self._offset
217217
obj._write_u8(self._address, reg_value)
@@ -262,7 +262,7 @@ def __init__(
262262
agc: bool = False,
263263
crc: bool = True
264264
) -> None:
265-
self.high_power: bool = high_power
265+
self.high_power = high_power
266266
# Device support SPI mode 0 (polarity & phase = 0) up to a max of 10mhz.
267267
# Set Default Baudrate to 5MHz to avoid problems
268268
self._device: spidev.SPIDevice = spidev.SPIDevice(
@@ -276,7 +276,7 @@ def __init__(
276276
self.reset()
277277
# No device type check! Catch an error from the very first request and
278278
# throw a nicer message to indicate possible wiring problems.
279-
version: int = self._read_u8(_RH_RF95_REG_42_VERSION)
279+
version = self._read_u8(_RH_RF95_REG_42_VERSION)
280280
if version != 18:
281281
raise RuntimeError(
282282
"Failed to find rfm9x with expected version -- check wiring"
@@ -298,78 +298,78 @@ def __init__(
298298
# Set mode idle
299299
self.idle()
300300
# Set frequency
301-
self.frequency_mhz: float = frequency
301+
self.frequency_mhz = frequency
302302
# Set preamble length (default 8 bytes to match radiohead).
303-
self.preamble_length: int = preamble_length
303+
self.preamble_length = preamble_length
304304
# Defaults set modem config to RadioHead compatible Bw125Cr45Sf128 mode.
305-
self.signal_bandwidth: int = 125000
306-
self.coding_rate: int = 5
307-
self.spreading_factor: int = 7
305+
self.signal_bandwidth = 125000
306+
self.coding_rate = 5
307+
self.spreading_factor = 7
308308
# Default to enable CRC checking on incoming packets.
309-
self.enable_crc: bool = crc
309+
self.enable_crc = crc
310310
"""CRC Enable state"""
311311
# set AGC - Default = False
312312
self.auto_agc = agc
313313
"""Automatic Gain Control state"""
314314
# Set transmit power to 13 dBm, a safe value any module supports.
315-
self.tx_power: int = 13
315+
self.tx_power = 13
316316
# initialize last RSSI reading
317-
self.last_rssi: float = 0.0
317+
self.last_rssi = 0.0
318318
"""The RSSI of the last received packet. Stored when the packet was received.
319319
The instantaneous RSSI value may not be accurate once the
320320
operating mode has been changed.
321321
"""
322-
self.last_snr: float = 0.0
322+
self.last_snr = 0.0
323323
"""The SNR of the last received packet. Stored when the packet was received.
324324
The instantaneous SNR value may not be accurate once the
325325
operating mode has been changed.
326326
"""
327327
# initialize timeouts and delays delays
328-
self.ack_wait: float = 0.5
328+
self.ack_wait = 0.5
329329
"""The delay time before attempting a retry after not receiving an ACK"""
330-
self.receive_timeout: float = 0.5
330+
self.receive_timeout = 0.5
331331
"""The amount of time to poll for a received packet.
332332
If no packet is received, the returned packet will be None
333333
"""
334-
self.xmit_timeout: float = 2.0
334+
self.xmit_timeout = 2.0
335335
"""The amount of time to wait for the HW to transmit the packet.
336336
This is mainly used to prevent a hang due to a HW issue
337337
"""
338-
self.ack_retries: int = 5
338+
self.ack_retries = 5
339339
"""The number of ACK retries before reporting a failure."""
340-
self.ack_delay: Optional[float] = None
340+
self.ack_delay = None
341341
"""The delay time before attemting to send an ACK.
342342
If ACKs are being missed try setting this to .1 or .2.
343343
"""
344344
# initialize sequence number counter for reliabe datagram mode
345-
self.sequence_number: int = 0
345+
self.sequence_number = 0
346346
# create seen Ids list
347-
self.seen_ids: bytearray = bytearray(256)
347+
self.seen_ids = bytearray(256)
348348
# initialize packet header
349349
# node address - default is broadcast
350-
self.node: int = _RH_BROADCAST_ADDRESS
350+
self.node = _RH_BROADCAST_ADDRESS
351351
"""The default address of this Node. (0-255).
352352
If not 255 (0xff) then only packets address to this node will be accepted.
353353
First byte of the RadioHead header.
354354
"""
355355
# destination address - default is broadcast
356-
self.destination: int = _RH_BROADCAST_ADDRESS
356+
self.destination = _RH_BROADCAST_ADDRESS
357357
"""The default destination address for packet transmissions. (0-255).
358358
If 255 (0xff) then any receiving node should accept the packet.
359359
Second byte of the RadioHead header.
360360
"""
361361
# ID - contains seq count for reliable datagram mode
362-
self.identifier: int = 0
362+
self.identifier = 0
363363
"""Automatically set to the sequence number when send_with_ack() used.
364364
Third byte of the RadioHead header.
365365
"""
366366
# flags - identifies ack/reetry packet for reliable datagram mode
367-
self.flags: int = 0
367+
self.flags = 0
368368
"""Upper 4 bits reserved for use by Reliable Datagram Mode.
369369
Lower 4 bits may be used to pass information.
370370
Fourth byte of the RadioHead header.
371371
"""
372-
self.crc_error_count: int = 0
372+
self.crc_error_count = 0
373373

374374
# pylint: disable=no-member
375375
# Reconsider pylint: disable when this can be tested
@@ -530,7 +530,7 @@ def rssi(self) -> int:
530530
"""The received strength indicator (in dBm) of the last received message."""
531531
# Read RSSI register and convert to value using formula in datasheet.
532532
# Remember in LoRa mode the payload register changes function to RSSI!
533-
raw_rssi: int = self._read_u8(_RH_RF95_REG_1A_PKT_RSSI_VALUE)
533+
raw_rssi = self._read_u8(_RH_RF95_REG_1A_PKT_RSSI_VALUE)
534534
if self.low_frequency_mode:
535535
raw_rssi -= 157
536536
else:
@@ -542,7 +542,7 @@ def snr(self) -> float:
542542
"""The SNR (in dB) of the last received message."""
543543
# Read SNR 0x19 register and convert to value using formula in datasheet.
544544
# SNR(dB) = PacketSnr [twos complement] / 4
545-
snr_byte: int = self._read_u8(_RH_RF95_REG_19_PKT_SNR_VALUE)
545+
snr_byte = self._read_u8(_RH_RF95_REG_19_PKT_SNR_VALUE)
546546
if snr_byte > 127:
547547
snr_byte = (256 - snr_byte) * -1
548548
return snr_byte / 4
@@ -553,7 +553,7 @@ def signal_bandwidth(self) -> int:
553553
value to increase throughput or to a lower value to increase the
554554
likelihood of successfully received payloads). Valid values are
555555
listed in RFM9x.bw_bins."""
556-
bw_id: int = (self._read_u8(_RH_RF95_REG_1D_MODEM_CONFIG1) & 0xF0) >> 4
556+
bw_id = (self._read_u8(_RH_RF95_REG_1D_MODEM_CONFIG1) & 0xF0) >> 4
557557
if bw_id >= len(self.bw_bins):
558558
current_bandwidth = 500000
559559
else:
@@ -563,8 +563,6 @@ def signal_bandwidth(self) -> int:
563563
@signal_bandwidth.setter
564564
def signal_bandwidth(self, val: int) -> None:
565565
# Set signal bandwidth (set to 125000 to match RadioHead Bw125).
566-
bw_id: int
567-
cutoff: int
568566
for bw_id, cutoff in enumerate(self.bw_bins):
569567
if val <= cutoff:
570568
break
@@ -603,7 +601,7 @@ def coding_rate(self) -> int:
603601
correction (try setting to a higher value to increase tolerance of
604602
short bursts of interference or to a lower value to increase bit
605603
rate). Valid values are limited to 5, 6, 7, or 8."""
606-
cr_id: int = (self._read_u8(_RH_RF95_REG_1D_MODEM_CONFIG1) & 0x0E) >> 1
604+
cr_id = (self._read_u8(_RH_RF95_REG_1D_MODEM_CONFIG1) & 0x0E) >> 1
607605
denominator = cr_id + 4
608606
return denominator
609607

@@ -681,7 +679,7 @@ def crc_error(self) -> int:
681679
# pylint: disable=too-many-branches
682680
def send(
683681
self,
684-
data: Any,
682+
data,
685683
*,
686684
keep_listening: bool = False,
687685
destination=None,
@@ -760,7 +758,7 @@ def send(
760758
self._write_u8(_RH_RF95_REG_12_IRQ_FLAGS, 0xFF)
761759
return not timed_out
762760

763-
def send_with_ack(self, data: Any) -> bool:
761+
def send_with_ack(self, data) -> bool:
764762
"""Reliable Datagram mode:
765763
Send a packet with data and wait for an ACK response.
766764
The packet header is automatically generated.
@@ -770,7 +768,7 @@ def send_with_ack(self, data: Any) -> bool:
770768
retries_remaining = self.ack_retries
771769
else:
772770
retries_remaining = 1
773-
got_ack: bool = False
771+
got_ack = False
774772
self.sequence_number = (self.sequence_number + 1) & 0xFF
775773
while not got_ack and retries_remaining:
776774
self.identifier = self.sequence_number
@@ -804,7 +802,7 @@ def receive(
804802
with_header: bool = False,
805803
with_ack: bool = False,
806804
timeout: Optional[float] = None
807-
):
805+
) -> Optional[bytearray]:
808806
"""Wait to receive a packet from the receiver. If a packet is found the payload bytes
809807
are returned, otherwise None is returned (which indicates the timeout elapsed with no
810808
reception).
@@ -841,7 +839,7 @@ def receive(
841839
if time.monotonic() - start >= timeout:
842840
timed_out = True
843841
# Payload ready is set, a packet is in the FIFO.
844-
packet: Optional[bytearray] = None
842+
packet = None
845843
# save last RSSI reading
846844
self.last_rssi = self.rssi
847845

0 commit comments

Comments
 (0)