File tree Expand file tree Collapse file tree 4 files changed +32
-9
lines changed Expand file tree Collapse file tree 4 files changed +32
-9
lines changed Original file line number Diff line number Diff line change @@ -83,10 +83,10 @@ def showInfo(self, file=sys.stdout):
8383 nodes = ""
8484 if self .nodes :
8585 for n in self .nodes .values ():
86- # when the TBeam is first booted, it sometimes shows the ' raw' data
86+ # when the TBeam is first booted, it sometimes shows the raw data
8787 # so, we will just remove any raw keys
88- n2 = remove_keys_from_dict ('raw' , n )
89- n2 = remove_keys_from_dict ('decode' , n2 )
88+ keys_to_remove = ('raw' , 'decoded' , 'payload' )
89+ n2 = remove_keys_from_dict (keys_to_remove , n )
9090
9191 # if we have 'macaddr', re-format it
9292 if 'macaddr' in n2 ['user' ]:
Original file line number Diff line number Diff line change @@ -184,6 +184,23 @@ def test_remove_keys_from_dict():
184184 assert remove_keys_from_dict (('b' ), {'a' :1 , 'b' :2 }) == {'a' :1 }
185185
186186
187+ @pytest .mark .unit
188+ def test_remove_keys_from_dict_multiple_keys ():
189+ """Test remove_keys_from_dict()"""
190+ keys = ('a' , 'b' )
191+ adict = {'a' : 1 , 'b' : 2 , 'c' : 3 }
192+ assert remove_keys_from_dict (keys , adict ) == {'c' :3 }
193+
194+
195+ @pytest .mark .unit
196+ def test_remove_keys_from_dict_nested ():
197+ """Test remove_keys_from_dict()"""
198+ keys = ('b' )
199+ adict = {'a' : {'b' : 1 }, 'b' : 2 , 'c' : 3 }
200+ exp = {'a' : {}, 'c' : 3 }
201+ assert remove_keys_from_dict (keys , adict ) == exp
202+
203+
187204@pytest .mark .unitslow
188205def test_Timeout_not_found ():
189206 """Test Timeout()"""
Original file line number Diff line number Diff line change @@ -204,12 +204,18 @@ def support_info():
204204
205205
206206def remove_keys_from_dict (keys , adict ):
207- """Return a dictionary without some keys in it."""
208- newdict = adict
207+ """Return a dictionary without some keys in it.
208+ Will removed nested keys.
209+ """
209210 for key in keys :
210- if key in adict :
211- del newdict [key ]
212- return newdict
211+ try :
212+ del adict [key ]
213+ except :
214+ pass
215+ for val in adict .values ():
216+ if isinstance (val , dict ):
217+ remove_keys_from_dict (keys , val )
218+ return adict
213219
214220
215221def hexstr (barray ):
Original file line number Diff line number Diff line change 1212# This call to setup() does all the work
1313setup (
1414 name = "meshtastic" ,
15- version = "1.2.50 " ,
15+ version = "1.2.51 " ,
1616 description = "Python API & client shell for talking to Meshtastic devices" ,
1717 long_description = long_description ,
1818 long_description_content_type = "text/markdown" ,
You can’t perform that action at this time.
0 commit comments