88import platform
99import sys
1010import time
11+ from typing import List
1112
1213import pyqrcode # type: ignore[import-untyped]
1314import yaml
2223from meshtastic .ble_interface import BLEInterface
2324from meshtastic .mesh_interface import MeshInterface
2425
25- def onReceive (packet , interface ):
26+ def onReceive (packet , interface ) -> None :
2627 """Callback invoked when a packet arrives"""
2728 args = mt_config .args
2829 try :
@@ -53,7 +54,7 @@ def onReceive(packet, interface):
5354 print (f"Warning: There is no field { ex } in the packet." )
5455
5556
56- def onConnection (interface , topic = pub .AUTO_TOPIC ): # pylint: disable=W0613
57+ def onConnection (interface , topic = pub .AUTO_TOPIC ) -> None : # pylint: disable=W0613
5758 """Callback invoked when we connect/disconnect from a radio"""
5859 print (f"Connection changed: { topic .getName ()} " )
5960
@@ -63,7 +64,7 @@ def checkChannel(interface: MeshInterface, channelIndex: int) -> bool:
6364 logging .debug (f"ch:{ ch } " )
6465 return (ch and ch .role != channel_pb2 .Channel .Role .DISABLED )
6566
66- def getPref (node , comp_name ):
67+ def getPref (node , comp_name ) -> bool :
6768 """Get a channel or preferences value"""
6869
6970 name = splitCompoundName (comp_name )
@@ -78,11 +79,11 @@ def getPref(node, comp_name):
7879 # First validate the input
7980 localConfig = node .localConfig
8081 moduleConfig = node .moduleConfig
81- found = False
82+ found : bool = False
8283 for config in [localConfig , moduleConfig ]:
8384 objDesc = config .DESCRIPTOR
8485 config_type = objDesc .fields_by_name .get (name [0 ])
85- pref = False
86+ pref = False #FIXME - checkme - Used here as boolean, but set 2 lines below as a string.
8687 if config_type :
8788 pref = config_type .message_type .fields_by_name .get (snake_name )
8889 if pref or wholeField :
@@ -129,15 +130,15 @@ def getPref(node, comp_name):
129130 return True
130131
131132
132- def splitCompoundName (comp_name ) :
133+ def splitCompoundName (comp_name : str ) -> List [ str ] :
133134 """Split compound (dot separated) preference name into parts"""
134- name = comp_name .split ("." )
135+ name : List [ str ] = comp_name .split ("." )
135136 if len (name ) < 2 :
136137 name [0 ] = comp_name
137138 name .append (comp_name )
138139 return name
139140
140- def traverseConfig (config_root , config , interface_config ):
141+ def traverseConfig (config_root , config , interface_config ) -> bool :
141142 """Iterate through current config level preferences and either traverse deeper if preference is a dict or set preference"""
142143 snake_name = meshtastic .util .camel_to_snake (config_root )
143144 for pref in config :
@@ -884,7 +885,7 @@ def setSimpleConfig(modem_preset):
884885 sys .exit (1 )
885886
886887
887- def printConfig (config ):
888+ def printConfig (config ) -> None :
888889 """print configuration"""
889890 objDesc = config .DESCRIPTOR
890891 for config_section in objDesc .fields :
@@ -901,12 +902,12 @@ def printConfig(config):
901902 print (f" { temp_name } " )
902903
903904
904- def onNode (node ):
905+ def onNode (node ) -> None :
905906 """Callback invoked when the node DB changes"""
906907 print (f"Node changed: { node } " )
907908
908909
909- def subscribe ():
910+ def subscribe () -> None :
910911 """Subscribe to the topics the user probably wants to see, prints output to stdout"""
911912 pub .subscribe (onReceive , "meshtastic.receive" )
912913 # pub.subscribe(onConnection, "meshtastic.connection")
@@ -917,7 +918,7 @@ def subscribe():
917918 # pub.subscribe(onNode, "meshtastic.node")
918919
919920
920- def export_config (interface ):
921+ def export_config (interface ) -> str :
921922 """used in --export-config"""
922923 configObj = {}
923924
@@ -949,7 +950,7 @@ def export_config(interface):
949950 if alt :
950951 configObj ["location" ]["alt" ] = alt
951952
952- config = MessageToDict (interface .localNode .localConfig )
953+ config = MessageToDict (interface .localNode .localConfig ) #checkme - Used as a dictionary here and a string below
953954 if config :
954955 # Convert inner keys to correct snake/camelCase
955956 prefs = {}
@@ -959,7 +960,7 @@ def export_config(interface):
959960 else :
960961 prefs [pref ] = config [pref ]
961962 if mt_config .camel_case :
962- configObj ["config" ] = config
963+ configObj ["config" ] = config #Identical command here and 2 lines below?
963964 else :
964965 configObj ["config" ] = config
965966
@@ -975,10 +976,10 @@ def export_config(interface):
975976 else :
976977 configObj ["module_config" ] = prefs
977978
978- config = "# start of Meshtastic configure yaml\n "
979- config += yaml .dump (configObj )
980- print (config )
981- return config
979+ config_txt = "# start of Meshtastic configure yaml\n " #checkme - "config" (now changed to config_out) was used as a string here and a Dictionary above
980+ config_txt += yaml .dump (configObj )
981+ print (config_txt )
982+ return config_txt
982983
983984
984985def common ():
0 commit comments