1111import platform
1212import sys
1313import time
14- from typing import Optional
14+ from typing import List , Optional
1515
1616import pyqrcode # type: ignore[import-untyped]
1717import yaml
4242from meshtastic .protobuf import channel_pb2 , config_pb2 , portnums_pb2
4343from meshtastic .version import get_active_version
4444
45- def onReceive (packet , interface ):
45+ def onReceive (packet , interface ) -> None :
4646 """Callback invoked when a packet arrives"""
4747 args = mt_config .args
4848 try :
@@ -73,7 +73,7 @@ def onReceive(packet, interface):
7373 print (f"Warning: There is no field { ex } in the packet." )
7474
7575
76- def onConnection (interface , topic = pub .AUTO_TOPIC ): # pylint: disable=W0613
76+ def onConnection (interface , topic = pub .AUTO_TOPIC ) -> None : # pylint: disable=W0613
7777 """Callback invoked when we connect/disconnect from a radio"""
7878 print (f"Connection changed: { topic .getName ()} " )
7979
@@ -85,7 +85,7 @@ def checkChannel(interface: MeshInterface, channelIndex: int) -> bool:
8585 return ch and ch .role != channel_pb2 .Channel .Role .DISABLED
8686
8787
88- def getPref (node , comp_name ):
88+ def getPref (node , comp_name ) -> bool :
8989 """Get a channel or preferences value"""
9090 def _printSetting (config_type , uni_name , pref_value , repeated ):
9191 """Pretty print the setting"""
@@ -109,11 +109,11 @@ def _printSetting(config_type, uni_name, pref_value, repeated):
109109 # First validate the input
110110 localConfig = node .localConfig
111111 moduleConfig = node .moduleConfig
112- found = False
112+ found : bool = False
113113 for config in [localConfig , moduleConfig ]:
114114 objDesc = config .DESCRIPTOR
115115 config_type = objDesc .fields_by_name .get (name [0 ])
116- pref = False
116+ pref = "" #FIXME - is this correct to leave as an empty string if not found?
117117 if config_type :
118118 pref = config_type .message_type .fields_by_name .get (snake_name )
119119 if pref or wholeField :
@@ -130,7 +130,7 @@ def _printSetting(config_type, uni_name, pref_value, repeated):
130130 return False
131131
132132 # Check if we need to request the config
133- if len (config .ListFields ()) != 0 :
133+ if len (config .ListFields ()) != 0 and not isinstance ( pref , str ): # if str, it's still the empty string, I think
134134 # read the value
135135 config_values = getattr (config , config_type .name )
136136 if not wholeField :
@@ -148,16 +148,16 @@ def _printSetting(config_type, uni_name, pref_value, repeated):
148148 return True
149149
150150
151- def splitCompoundName (comp_name ) :
151+ def splitCompoundName (comp_name : str ) -> List [ str ] :
152152 """Split compound (dot separated) preference name into parts"""
153- name = comp_name .split ("." )
153+ name : List [ str ] = comp_name .split ("." )
154154 if len (name ) < 2 :
155155 name [0 ] = comp_name
156156 name .append (comp_name )
157157 return name
158158
159159
160- def traverseConfig (config_root , config , interface_config ):
160+ def traverseConfig (config_root , config , interface_config ) -> bool :
161161 """Iterate through current config level preferences and either traverse deeper if preference is a dict or set preference"""
162162 snake_name = meshtastic .util .camel_to_snake (config_root )
163163 for pref in config :
@@ -958,7 +958,7 @@ def setSimpleConfig(modem_preset):
958958 sys .exit (1 )
959959
960960
961- def printConfig (config ):
961+ def printConfig (config ) -> None :
962962 """print configuration"""
963963 objDesc = config .DESCRIPTOR
964964 for config_section in objDesc .fields :
@@ -975,12 +975,12 @@ def printConfig(config):
975975 print (f" { temp_name } " )
976976
977977
978- def onNode (node ):
978+ def onNode (node ) -> None :
979979 """Callback invoked when the node DB changes"""
980980 print (f"Node changed: { node } " )
981981
982982
983- def subscribe ():
983+ def subscribe () -> None :
984984 """Subscribe to the topics the user probably wants to see, prints output to stdout"""
985985 pub .subscribe (onReceive , "meshtastic.receive" )
986986 # pub.subscribe(onConnection, "meshtastic.connection")
@@ -991,7 +991,7 @@ def subscribe():
991991 # pub.subscribe(onNode, "meshtastic.node")
992992
993993
994- def export_config (interface ):
994+ def export_config (interface ) -> str :
995995 """used in --export-config"""
996996 configObj = {}
997997
@@ -1023,7 +1023,7 @@ def export_config(interface):
10231023 if alt :
10241024 configObj ["location" ]["alt" ] = alt
10251025
1026- config = MessageToDict (interface .localNode .localConfig )
1026+ config = MessageToDict (interface .localNode .localConfig ) #checkme - Used as a dictionary here and a string below
10271027 if config :
10281028 # Convert inner keys to correct snake/camelCase
10291029 prefs = {}
@@ -1042,7 +1042,7 @@ def export_config(interface):
10421042 for i in range (len (prefs [pref ]['adminKey' ])):
10431043 prefs [pref ]['adminKey' ][i ] = 'base64:' + prefs [pref ]['adminKey' ][i ]
10441044 if mt_config .camel_case :
1045- configObj ["config" ] = config
1045+ configObj ["config" ] = config #Identical command here and 2 lines below?
10461046 else :
10471047 configObj ["config" ] = config
10481048
@@ -1058,10 +1058,11 @@ def export_config(interface):
10581058 else :
10591059 configObj ["module_config" ] = prefs
10601060
1061- config = "# start of Meshtastic configure yaml\n "
1062- config += yaml .dump (configObj )
1063- print (config )
1064- return config
1061+ config_txt = "# start of Meshtastic configure yaml\n " #checkme - "config" (now changed to config_out)
1062+ #was used as a string here and a Dictionary above
1063+ config_txt += yaml .dump (configObj )
1064+ print (config_txt )
1065+ return config_txt
10651066
10661067
10671068def create_power_meter ():
0 commit comments