mirror of
https://github.com/meshtastic/python.git
synced 2025-12-30 03:17:54 -05:00
Merge pull request #411 from mkinney/fix_pylint_warnings
fix pylint warnings
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
|
||||
# Add files or directories matching the regex patterns to the blacklist. The
|
||||
# regex matches against base names, not paths.
|
||||
ignore-patterns=mqtt_pb2.py,channel_pb2.py,telemetry_pb2.py,admin_pb2.py,config_pb2.py,deviceonly_pb2.py,apponly_pb2.py,remote_hardware_pb2.py,portnums_pb2.py,mesh_pb2.py,storeforward_pb2.py,cannedmessages_pb2.py,module_config_pb2.py,localonly_pb2.py,node.py
|
||||
ignore-patterns=mqtt_pb2.py,channel_pb2.py,telemetry_pb2.py,admin_pb2.py,config_pb2.py,deviceonly_pb2.py,apponly_pb2.py,remote_hardware_pb2.py,portnums_pb2.py,mesh_pb2.py,storeforward_pb2.py,cannedmessages_pb2.py,module_config_pb2.py,localonly_pb2.py,node.py,device_metadata_pb2.py
|
||||
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ ignore-patterns=mqtt_pb2.py,channel_pb2.py,telemetry_pb2.py,admin_pb2.py,config_
|
||||
# no Warning level messages displayed, use"--disable=all --enable=classes
|
||||
# --disable=W"
|
||||
#
|
||||
disable=invalid-name,fixme,logging-fstring-interpolation,too-many-statements,too-many-branches,too-many-locals,no-member,f-string-without-interpolation,protected-access,no-self-use,pointless-string-statement,too-few-public-methods,broad-except,no-else-return,no-else-raise,bare-except,too-many-public-methods
|
||||
disable=invalid-name,fixme,logging-fstring-interpolation,too-many-statements,too-many-branches,too-many-locals,no-member,f-string-without-interpolation,protected-access,pointless-string-statement,too-few-public-methods,broad-except,no-else-return,no-else-raise,bare-except,too-many-public-methods
|
||||
|
||||
[BASIC]
|
||||
|
||||
|
||||
@@ -182,7 +182,7 @@ protocols = {
|
||||
portnums_pb2.PortNum.ADMIN_APP: KnownProtocol("admin", admin_pb2.AdminMessage),
|
||||
portnums_pb2.PortNum.ROUTING_APP: KnownProtocol("routing", mesh_pb2.Routing),
|
||||
portnums_pb2.PortNum.TELEMETRY_APP: KnownProtocol("telemetry", telemetry_pb2.Telemetry),
|
||||
portnums_pb2.PortNum.REMOTE_HARDWARE_APP: KnownProtocol("remotehw", remote_hardware_pb2.HardwareMessage),
|
||||
portnums_pb2.PortNum.REMOTE_HARDWARE_APP: KnownProtocol("remotehw", remote_hardware_pb2.HardwareMessage),
|
||||
portnums_pb2.PortNum.SIMULATOR_APP: KnownProtocol("simulator", mesh_pb2.Compressed),
|
||||
portnums_pb2.PortNum.TRACEROUTE_APP: KnownProtocol("traceroute", mesh_pb2.RouteDiscovery)
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ def onConnected(interface):
|
||||
alt = 0
|
||||
lat = 0.0
|
||||
lon = 0.0
|
||||
# TODO: use getNode(args.dest) to be able to set it for a remote node
|
||||
# TODO: use getNode(args.dest) to be able to set it for a remote node
|
||||
localConfig = interface.localNode.localConfig
|
||||
if args.setalt:
|
||||
alt = int(args.setalt)
|
||||
@@ -282,17 +282,17 @@ def onConnected(interface):
|
||||
if args.reboot_ota:
|
||||
closeNow = True
|
||||
waitForAckNak = True
|
||||
interface.getNode(args.dest, False).rebootOTA();
|
||||
interface.getNode(args.dest, False).rebootOTA()
|
||||
|
||||
if args.shutdown:
|
||||
closeNow = True
|
||||
waitForAckNak = True
|
||||
interface.getNode(args.dest, False).shutdown()
|
||||
|
||||
|
||||
if args.device_metadata:
|
||||
closeNow = True
|
||||
interface.getNode(args.dest).getMetadata()
|
||||
|
||||
|
||||
if args.begin_edit:
|
||||
closeNow = True
|
||||
interface.getNode(args.dest, False).beginSettingsTransaction()
|
||||
@@ -336,7 +336,7 @@ def onConnected(interface):
|
||||
dest = str(args.traceroute)
|
||||
print(f"Sending traceroute request to {dest} (this could take a while)")
|
||||
interface.sendTraceRoute(dest, hopLimit)
|
||||
|
||||
|
||||
if args.gpio_wrb or args.gpio_rd or args.gpio_watch:
|
||||
if args.dest == BROADCAST_ADDR:
|
||||
meshtastic.util.our_exit("Warning: Must use a destination node ID.")
|
||||
@@ -454,7 +454,7 @@ def onConnected(interface):
|
||||
for pref in configuration['config'][section]:
|
||||
setPref(localConfig, f"{section}.{pref}", str(configuration['config'][section][pref]))
|
||||
interface.getNode(args.dest).writeConfig(section)
|
||||
|
||||
|
||||
if 'module_config' in configuration:
|
||||
moduleConfig = interface.getNode(args.dest).moduleConfig
|
||||
for section in configuration['module_config']:
|
||||
@@ -648,6 +648,7 @@ def onConnected(interface):
|
||||
interface.close() # close the connection now, so that our app exits
|
||||
|
||||
def printConfig(config):
|
||||
"""print configuration"""
|
||||
objDesc = config.DESCRIPTOR
|
||||
for config_section in objDesc.fields:
|
||||
if config_section.name != "version":
|
||||
@@ -720,7 +721,7 @@ def export_config(interface):
|
||||
configObj["config"] = config
|
||||
else:
|
||||
configObj["config"] = config
|
||||
|
||||
|
||||
module_config = MessageToDict(interface.localNode.moduleConfig)
|
||||
if module_config:
|
||||
# Convert inner keys to correct snake/camelCase
|
||||
@@ -946,7 +947,7 @@ def initParser():
|
||||
"--traceroute", help="Traceroute from connected node to a destination. " \
|
||||
"You need pass the destination ID as argument, like " \
|
||||
"this: '--traceroute !ba4bf9d0' " \
|
||||
"Only nodes that have the encryption key can be traced.")
|
||||
"Only nodes that have the encryption key can be traced.")
|
||||
|
||||
parser.add_argument(
|
||||
"--reboot", help="Tell the destination node to reboot", action="store_true")
|
||||
@@ -959,7 +960,7 @@ def initParser():
|
||||
|
||||
parser.add_argument(
|
||||
"--device-metadata", help="Get the device metadata from the node", action="store_true")
|
||||
|
||||
|
||||
parser.add_argument(
|
||||
"--begin-edit", help="Tell the node to open a transaction to edit settings", action="store_true")
|
||||
|
||||
@@ -968,7 +969,7 @@ def initParser():
|
||||
|
||||
parser.add_argument(
|
||||
"--factory-reset", help="Tell the destination node to install the default config", action="store_true")
|
||||
|
||||
|
||||
parser.add_argument(
|
||||
"--reset-nodedb", help="Tell the destination node clear its list of nodes", action="store_true")
|
||||
|
||||
|
||||
@@ -165,10 +165,10 @@ class MeshInterface:
|
||||
n = meshtastic.node.Node(self, nodeId)
|
||||
# Only request device settings and channel info when necessary
|
||||
if requestConfig:
|
||||
logging.debug("About to requestConfig")
|
||||
n.requestConfig()
|
||||
if not n.waitForConfig():
|
||||
our_exit("Error: Timed out waiting for node config")
|
||||
logging.debug("About to requestConfig")
|
||||
n.requestConfig()
|
||||
if not n.waitForConfig():
|
||||
our_exit("Error: Timed out waiting for node config")
|
||||
return n
|
||||
|
||||
def sendText(self, text: AnyStr,
|
||||
@@ -291,16 +291,18 @@ class MeshInterface:
|
||||
portNum=portnums_pb2.PortNum.POSITION_APP,
|
||||
wantAck=wantAck,
|
||||
wantResponse=wantResponse)
|
||||
|
||||
|
||||
def sendTraceRoute(self, dest, hopLimit):
|
||||
"""Send the trace route"""
|
||||
r = mesh_pb2.RouteDiscovery()
|
||||
self.sendData(r, destinationId=dest, portNum=portnums_pb2.PortNum.TRACEROUTE_APP,
|
||||
wantResponse=True, onResponse=self.onResponseTraceRoute)
|
||||
# extend timeout based on number of nodes, limit by configured hopLimit
|
||||
waitFactor = min(len(self.nodes)-1, hopLimit)
|
||||
waitFactor = min(len(self.nodes)-1, hopLimit)
|
||||
self.waitForTraceRoute(waitFactor)
|
||||
|
||||
def onResponseTraceRoute(self, p):
|
||||
"""on response for trace route"""
|
||||
routeDiscovery = mesh_pb2.RouteDiscovery()
|
||||
routeDiscovery.ParseFromString(p["decoded"]["payload"])
|
||||
asDict = google.protobuf.json_format.MessageToDict(routeDiscovery)
|
||||
@@ -308,8 +310,8 @@ class MeshInterface:
|
||||
print("Route traced:")
|
||||
routeStr = self._nodeNumToId(p["to"])
|
||||
if "route" in asDict:
|
||||
for nodeNum in asDict["route"]:
|
||||
routeStr += " --> " + self._nodeNumToId(nodeNum)
|
||||
for nodeNum in asDict["route"]:
|
||||
routeStr += " --> " + self._nodeNumToId(nodeNum)
|
||||
routeStr += " --> " + self._nodeNumToId(p["from"])
|
||||
print(routeStr)
|
||||
|
||||
@@ -384,11 +386,13 @@ class MeshInterface:
|
||||
raise Exception("Timed out waiting for interface config")
|
||||
|
||||
def waitForAckNak(self):
|
||||
"""Wait for the ack/nak"""
|
||||
success = self._timeout.waitForAckNak(self._acknowledgment)
|
||||
if not success:
|
||||
raise Exception("Timed out waiting for an acknowledgment")
|
||||
|
||||
def waitForTraceRoute(self, waitFactor):
|
||||
"""Wait for trace route"""
|
||||
success = self._timeout.waitForTraceRoute(waitFactor, self._acknowledgment)
|
||||
if not success:
|
||||
raise Exception("Timed out waiting for traceroute")
|
||||
@@ -745,7 +749,7 @@ class MeshInterface:
|
||||
handler = self.responseHandlers.pop(requestId, None)
|
||||
if handler is not None:
|
||||
if not isAck or (isAck and handler.__name__ == "onAckNak"):
|
||||
handler.callback(asDict)
|
||||
handler.callback(asDict)
|
||||
|
||||
logging.debug(f"Publishing {topic}: packet={stripnl(asDict)} ")
|
||||
publishingThread.queueWork(lambda: pub.sendMessage(
|
||||
|
||||
@@ -172,7 +172,7 @@ class Timeout:
|
||||
def waitForTraceRoute(self, waitFactor, acknowledgment, attr='receivedTraceRoute'):
|
||||
"""Block until traceroute response is received. Returns True if traceroute response has been received."""
|
||||
self.expireTimeout *= waitFactor
|
||||
self.reset()
|
||||
self.reset()
|
||||
while time.time() < self.expireTime:
|
||||
if getattr(acknowledgment, attr, None):
|
||||
acknowledgment.reset()
|
||||
@@ -183,16 +183,18 @@ class Timeout:
|
||||
class Acknowledgment:
|
||||
"A class that records which type of acknowledgment was just received, if any."
|
||||
def __init__(self):
|
||||
self.receivedAck = False
|
||||
self.receivedNak = False
|
||||
self.receivedImplAck = False
|
||||
self.receivedTraceRoute = False
|
||||
"""initialize"""
|
||||
self.receivedAck = False
|
||||
self.receivedNak = False
|
||||
self.receivedImplAck = False
|
||||
self.receivedTraceRoute = False
|
||||
|
||||
def reset(self):
|
||||
self.receivedAck = False
|
||||
self.receivedNak = False
|
||||
self.receivedImplAck = False
|
||||
self.receivedTraceRoute = False
|
||||
"""reset"""
|
||||
self.receivedAck = False
|
||||
self.receivedNak = False
|
||||
self.receivedImplAck = False
|
||||
self.receivedTraceRoute = False
|
||||
|
||||
class DeferredExecution():
|
||||
"""A thread that accepts closures to run, and runs them as they are received"""
|
||||
|
||||
Reference in New Issue
Block a user