9090
9191# Radio class definition
9292class 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
523531def 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
537545class 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