Skip to content

Commit b32a4b8

Browse files
committed
fixed most pylint warnings, but also just added disables for some
1 parent afab24f commit b32a4b8

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

examples/rda5807m_simpletest.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# SPDX-FileCopyrightText: Copyright (c) 2022 tinkeringtech for TinkeringTech LLC
33
#
44
# SPDX-License-Identifier: Unlicense
5+
6+
# pylint: disable=global-statement, too-many-branches, too-many-statements
57
import time
68
import board
79
import busio
@@ -40,6 +42,7 @@ def textHandle(rdsText):
4042
rdstext = rdsText
4143
print(rdsText)
4244

45+
4346
rds.attach_text_callback(textHandle)
4447

4548
# Read input from serial
@@ -148,7 +151,7 @@ def runSerialCommand(cmd, value=0):
148151

149152

150153
print_rds = False
151-
radio.send_rds = rds.process_data
154+
radio.attach_send_rds_callback(rds.process_data)
152155
runSerialCommand("?", 0)
153156

154157
print("-> ", end="")

tinkeringtech_rda5807m.py

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@
9090

9191
# Radio class definition
9292
class Radio:
93+
# pylint: disable=too-many-instance-attributes
94+
# pylint: disable=too-many-public-methods
95+
9396
"""
9497
A class for communicating with the rda5807m chip
9598
@@ -138,6 +141,7 @@ class Radio:
138141
freq_low = 8700
139142
freq_high = 10800
140143
freq_steps = 10
144+
rssi = 0
141145

142146
# Set default frequency and volume
143147
def __init__(self, board, frequency=10000, volume=1):
@@ -288,7 +292,7 @@ def term(self):
288292
# Terminates all receiver functions
289293
self.set_volume(0)
290294
self.registers[RADIO_REG_CTRL] = 0x0000
291-
self.save_registers
295+
self.save_registers()
292296

293297
def set_bass_boost(self, switch_on):
294298
"""docstring."""
@@ -519,22 +523,29 @@ def read_registers(self):
519523
for i in range(6):
520524
self.registers[0xA + i] = self.read16()
521525

526+
def attach_send_rds_callback(self, new_function):
527+
"""docstring."""
528+
self.send_rds = new_function
529+
522530

523531
def replace_element(index, text, newchar):
524532
"""docstring."""
525533
# Replaces char in string at index with newchar
526534
newlist = list(text)
527-
if type(newchar) is int:
528-
if newchar < 127 and newchar > 31:
535+
if isinstance(newchar, int):
536+
newlist[index] = " "
537+
# this used to be an AND but that would make no sense. Changed to OR
538+
if newchar < 127 or newchar > 31:
529539
newlist[index] = chr(newchar)
530-
else:
531-
newlist[index] = " "
532540
else:
533541
newlist[index] = newchar
534542
return "".join(newlist)
535543

536544

537545
class RDSParser:
546+
# pylint: disable=too-many-instance-attributes
547+
# pylint: disable=too-many-branches
548+
# pylint: disable=too-many-statements
538549
"""
539550
A class used for parsing rds data into readable strings
540551
"""
@@ -603,11 +614,7 @@ def process_data(self, block1, block2, block3, block4):
603614
self.rds_tp = block2 & 0x0400
604615
self.rds_pty = block2 & 0x0400
605616

606-
# rdsGroupType cases
607-
if rds_group_type == 0x0A:
608-
pass
609-
610-
elif rds_group_type == 0x0B:
617+
if rds_group_type == 0x0B:
611618
# Data received is part of Service Station name
612619
idx = 2 * (block2 & 0x0003)
613620

@@ -618,12 +625,15 @@ def process_data(self, block1, block2, block3, block4):
618625
if (self.ps_name1[idx] == cdata_1) and (self.ps_name1[idx + 1] == cdata_2):
619626
self.ps_name2 = replace_element(idx, self.ps_name2, cdata_1)
620627
self.ps_name2 = replace_element(idx + 1, self.ps_name2, cdata_2)
621-
if (idx == 6) and (self.ps_name2 == self.ps_name1):
622-
if self.program_service_name != self.ps_name2:
623-
# Publish station name
624-
self.program_service_name = self.ps_name2
625-
if self.send_service_name:
626-
self.send_service_name(self.program_service_name)
628+
if (
629+
idx == 6
630+
and self.ps_name2 == self.ps_name1
631+
and self.program_service_name != self.ps_name2
632+
):
633+
# Publish station name
634+
self.program_service_name = self.ps_name2
635+
if self.send_service_name:
636+
self.send_service_name(self.program_service_name)
627637

628638
if (self.ps_name1[idx] != cdata_1) or (self.ps_name1[idx + 1] != cdata_2):
629639
self.ps_name1 = replace_element(idx, self.ps_name1, cdata_1)
@@ -633,9 +643,8 @@ def process_data(self, block1, block2, block3, block4):
633643
time.sleep(0.1)
634644
self.text_ab = block2 & 0x0010
635645
idx = 4 * (block2 & 0x000F)
636-
if idx < self.last_text_idx:
637-
if self.send_text:
638-
self.send_text(self.rds_text)
646+
if idx < self.last_text_idx and self.send_text:
647+
self.send_text(self.rds_text)
639648
self.last_text_idx = idx
640649

641650
if self.text_ab != self.last_text_ab:
@@ -673,3 +682,5 @@ def process_data(self, block1, block2, block3, block4):
673682
self.last_minutes_2 = self.last_minutes_1
674683
self.last_minutes_1 = mins
675684
self.send_time(mins // 60, mins % 60)
685+
686+
return 0

0 commit comments

Comments
 (0)