From ae2ef78560f21aa8cfe90dd58a9916e07498c614 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Wed, 3 Jul 2024 09:53:23 -0700 Subject: [PATCH] fix linter warnings (note: the linter test for min/max is buggy so disabled) --- .pylintrc | 2 +- meshtastic/__main__.py | 5 ++--- meshtastic/powermon/__init__.py | 2 +- meshtastic/powermon/ppk2.py | 5 +++-- meshtastic/powermon/stress.py | 29 ++++++++++++++++------------- meshtastic/slog/arrow.py | 2 +- meshtastic/slog/slog.py | 3 ++- 7 files changed, 26 insertions(+), 22 deletions(-) diff --git a/.pylintrc b/.pylintrc index 3201e41..c94cddf 100644 --- a/.pylintrc +++ b/.pylintrc @@ -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,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,nested-min-max [BASIC] diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index 3691359..f070849 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -854,7 +854,7 @@ def onConnected(interface): if args.slog_out or args.power_stress: # Setup loggers - global meter + global meter # pylint: disable=global-variable-not-assigned LogSet(interface, args.slog_out if args.slog_out != 'default' else None, meter) if args.power_stress: @@ -1001,9 +1001,8 @@ def export_config(interface): def create_power_meter(): """Setup the power meter.""" - global meter + global meter # pylint: disable=global-statement args = mt_config.args - meter = None # assume no power meter if args.power_riden: meter = RidenPowerSupply(args.power_riden) elif args.power_ppk2_supply or args.power_ppk2_meter: diff --git a/meshtastic/powermon/__init__.py b/meshtastic/powermon/__init__.py index aefc8ae..12826cc 100644 --- a/meshtastic/powermon/__init__.py +++ b/meshtastic/powermon/__init__.py @@ -4,4 +4,4 @@ from .power_supply import PowerError, PowerMeter, PowerSupply from .ppk2 import PPK2PowerSupply from .riden import RidenPowerSupply from .sim import SimPowerSupply -from .stress import PowerStress \ No newline at end of file +from .stress import PowerStress diff --git a/meshtastic/powermon/ppk2.py b/meshtastic/powermon/ppk2.py index 1e2504d..de400b9 100644 --- a/meshtastic/powermon/ppk2.py +++ b/meshtastic/powermon/ppk2.py @@ -9,7 +9,6 @@ from ppk2_api import ppk2_api # type: ignore[import-untyped] from .power_supply import PowerError, PowerSupply - class PPK2PowerSupply(PowerSupply): """Interface for talking with the NRF PPK2 high-resolution micro-power supply. Power Profiler Kit II is what you should google to find it for purchase. @@ -130,7 +129,9 @@ class PPK2PowerSupply(PowerSupply): # must be after setting source voltage and before setting mode self.r.start_measuring() # send command to ppk2 - if not s: # min power outpuf of PPK2. If less than this assume we want just meter mode. + if ( + not s + ): # min power outpuf of PPK2. If less than this assume we want just meter mode. self.r.use_ampere_meter() else: self.r.use_source_meter() # set source meter mode diff --git a/meshtastic/powermon/stress.py b/meshtastic/powermon/stress.py index 0ab8d7d..665e58b 100644 --- a/meshtastic/powermon/stress.py +++ b/meshtastic/powermon/stress.py @@ -3,10 +3,7 @@ import logging import time -from pubsub import pub # type: ignore[import-untyped] - -from meshtastic.protobuf import portnums_pb2 -from meshtastic.protobuf.powermon_pb2 import PowerStressMessage +from ..protobuf import ( portnums_pb2, powermon_pb2 ) def onPowerStressResponse(packet, interface): @@ -20,7 +17,7 @@ class PowerStressClient: The client stub for talking to the firmware PowerStress module. """ - def __init__(self, iface, node_id = None): + def __init__(self, iface, node_id=None): """ Create a new PowerStressClient instance. @@ -31,14 +28,18 @@ class PowerStressClient: if not node_id: node_id = iface.myInfo.my_node_num - self.node_id = node_id + self.node_id = node_id # No need to subscribe - because we # pub.subscribe(onGPIOreceive, "meshtastic.receive.powerstress") def sendPowerStress( - self, cmd: PowerStressMessage.Opcode.ValueType, num_seconds: float = 0.0, onResponse=None + self, + cmd: powermon_pb2.PowerStressMessage.Opcode.ValueType, + num_seconds: float = 0.0, + onResponse=None, ): - r = PowerStressMessage() + """Client goo for talking with the device side agent.""" + r = powermon_pb2.PowerStressMessage() r.cmd = cmd r.num_seconds = num_seconds @@ -49,16 +50,16 @@ class PowerStressClient: wantAck=True, wantResponse=True, onResponse=onResponse, - onResponseAckPermitted=True + onResponseAckPermitted=True, ) + class PowerStress: """Walk the UUT through a set of power states so we can capture repeatable power consumption measurements.""" def __init__(self, iface): self.client = PowerStressClient(iface) - def run(self): """Run the power stress test.""" # Send the power stress command @@ -68,11 +69,13 @@ class PowerStress: nonlocal gotAck gotAck = True - logging.info("Starting power stress test, attempting to contact UUT...") - self.client.sendPowerStress(PowerStressMessage.PRINT_INFO, onResponse=onResponse) + logging.info("Starting power stress test, attempting to contact UUT...") + self.client.sendPowerStress( + powermon_pb2.PowerStressMessage.PRINT_INFO, onResponse=onResponse + ) # Wait for the response while not gotAck: time.sleep(0.1) - logging.info("Power stress test complete.") \ No newline at end of file + logging.info("Power stress test complete.") diff --git a/meshtastic/slog/arrow.py b/meshtastic/slog/arrow.py index a2d32e6..0833704 100644 --- a/meshtastic/slog/arrow.py +++ b/meshtastic/slog/arrow.py @@ -4,7 +4,7 @@ import logging import os import pyarrow as pa -import pyarrow.feather as feather +from pyarrow import feather chunk_size = 1000 # disk writes are batched based on this number of rows diff --git a/meshtastic/slog/slog.py b/meshtastic/slog/slog.py index 9c6ae6d..d5c1998 100644 --- a/meshtastic/slog/slog.py +++ b/meshtastic/slog/slog.py @@ -118,7 +118,8 @@ class StructuredLogger: self.writer.close() f = self.raw_file self.raw_file = None # mark that we are shutting down - f.close() # Close the raw.txt file + if f: + f.close() # Close the raw.txt file def _onLogMessage(self, line: str) -> None: """Handle log messages.