Skip to content

Commit fb804e5

Browse files
committed
pylint: fix several pylint issues
Unused variable 'server_status' (unused-variable) Consider explicitly re-raising using the 'from' keyword (raise-missing-from) Use lazy % formatting in logging functions (logging-not-lazy) Possible unbalanced tuple unpacking with sequence defined at line 1629: left side has 3 label(s), right side has 2 value(s) (unbalanced-tuple-unpacking) Unnecessary "else" after "continue" (no-else-continue) Either all return statements in a function should return an expression, or none of them should. (inconsistent-return-statements) Consider using [] instead of list() (use-list-literal) Method 'name' was expected to be 'method', found it instead as 'property' (invalid-overridden-method) Consider merging these comparisons with "in" to 'node in (conn.node_a, conn.node_b)' (consider-using-in) Unused private member `AbstractXBeeDevice.__is_api_packet(xbee_packet)` (unused-private-member) Method could be a function (no-self-use) Unused private member `IPDevice.__DEFAULT_PROTOCOL` (unused-private-member) Unused private member `XBeeDevice.__TIMEOUT_ENTER_COMMAND_MODE` (unused-private-member) Unused private member `XBeeDevice.__COMMAND_MODE_CHAR` (unused-private-member) Unused private member `XBeeDevice.__COMMAND_MODE_OK` (unused-private-member) Unused private member `XBee64BitAddress.__DEVICE_ID_SEPARATOR` (unused-private-member) Unused private member `XBee64BitAddress.__DEVICE_ID_MAC_SEPARATOR` (unused-private-member) Unnecessary parens after 'not' keyword (superfluous-parens) Signed-off-by: Tatiana Leon <Tatiana.Leon@digi.com>
1 parent 00a2475 commit fb804e5

File tree

13 files changed

+125
-136
lines changed

13 files changed

+125
-136
lines changed

digi/xbee/devices.py

Lines changed: 14 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,8 @@ def __send_parameter(self, parameter, parameter_value=None, apply=None):
416416

417417
return response.response
418418

419-
def _check_at_cmd_response_is_valid(self, response):
419+
@staticmethod
420+
def _check_at_cmd_response_is_valid(response):
420421
"""
421422
Checks if the provided `ATCommandResponse` is valid throwing an
422423
:class:`.ATCommandException` in case it is not.
@@ -1222,7 +1223,7 @@ def get_io_configuration(self, io_line):
12221223
mode = IOMode(value[0])
12231224
except ValueError:
12241225
raise OperationNotSupportedException(
1225-
"Received configuration IO mode '%s' is invalid." % utils.hex_to_string(value))
1226+
"Received configuration IO mode '%s' is invalid." % utils.hex_to_string(value)) from None
12261227
return mode
12271228

12281229
def get_io_sampling_rate(self):
@@ -1340,7 +1341,7 @@ def io_sample_callback(received_packet):
13401341
try:
13411342
return IOSample(sample_payload)
13421343
except Exception as exc:
1343-
raise XBeeException("Could not create the IO sample.", exc)
1344+
raise XBeeException("Could not create the IO sample.", exc) from None
13441345

13451346
def get_adc_value(self, io_line):
13461347
"""
@@ -2033,22 +2034,6 @@ def _get_packet_by_id(self, frame_id):
20332034

20342035
return packet
20352036

2036-
@staticmethod
2037-
def __is_api_packet(xbee_packet):
2038-
"""
2039-
Determines whether the provided XBee packet is an API packet.
2040-
2041-
Returns:
2042-
Boolean: `True` if the provided XBee packet is an API packet (its
2043-
frame type is in :class:`.ApiFrameType` enum), `False` otherwise.
2044-
"""
2045-
aft = xbee_packet.get_frame_type()
2046-
try:
2047-
ApiFrameType.get(aft)
2048-
except ValueError:
2049-
return False
2050-
return True
2051-
20522037
def _add_packet_received_callback(self, callback):
20532038
"""
20542039
Adds a callback for the event :class:`.PacketReceived`.
@@ -2305,14 +2290,6 @@ class XBeeDevice(AbstractXBeeDevice):
23052290
supports API modes, not AT (transparent) mode).
23062291
"""
23072292

2308-
__TIMEOUT_ENTER_COMMAND_MODE = 1.5 # seconds
2309-
"""
2310-
Timeout to wait after entering in command mode in seconds.
2311-
2312-
It is used to determine the operating mode of the module (this library only
2313-
supports API modes, not transparent mode).
2314-
"""
2315-
23162293
__TIMEOUT_RESET = 5 # seconds
23172294
"""
23182295
Timeout to wait when resetting the module.
@@ -2323,16 +2300,6 @@ class XBeeDevice(AbstractXBeeDevice):
23232300
Timeout to read packets.
23242301
"""
23252302

2326-
__COMMAND_MODE_CHAR = "+"
2327-
"""
2328-
Character you have to send to enter AT command mode
2329-
"""
2330-
2331-
__COMMAND_MODE_OK = "OK\r"
2332-
"""
2333-
Response received if the attempt to enter in AT command mode goes well.
2334-
"""
2335-
23362303
def __init__(self, port=None, baud_rate=None, data_bits=serial.EIGHTBITS,
23372304
stop_bits=serial.STOPBITS_ONE, parity=serial.PARITY_NONE,
23382305
flow_control=FlowControl.NONE,
@@ -2460,7 +2427,7 @@ def open(self, force_settings=False):
24602427
"forcing settings using recovery: %s", str(exc))
24612428
if self._serial_port is None:
24622429
raise XBeeException("Can not open the port by forcing the settings, "
2463-
"it is only supported for Serial")
2430+
"it is only supported for Serial") from None
24642431
self._autodetect_device()
24652432
self.open(force_settings=False)
24662433

@@ -2475,7 +2442,7 @@ def _do_open(self):
24752442
the operating mode.
24762443
XBeeException: If the XBee is already opened.
24772444
"""
2478-
xbee_info = self._comm_iface.get_local_xbee_info() if self._comm_iface else None
2445+
xbee_info = self._comm_iface.get_local_xbee_info() if self._comm_iface else ()
24792446
if xbee_info:
24802447
self._operating_mode = OperatingMode.get(xbee_info[0])
24812448
self._hardware_version = HardwareVersion.get(xbee_info[1])
@@ -6196,8 +6163,6 @@ class IPDevice(XBeeDevice):
61966163

61976164
__DEFAULT_SOURCE_PORT = 9750
61986165

6199-
__DEFAULT_PROTOCOL = IPProtocol.TCP
6200-
62016166
__OPERATION_EXCEPTION = "Operation not supported in this module."
62026167

62036168
def __init__(self, port=None, baud_rate=None, data_bits=serial.EIGHTBITS,
@@ -7731,12 +7696,7 @@ def __get_signal_quality(wifi_version, signal_strength):
77317696
quality = 2 * signal_strength
77327697

77337698
# Check limits.
7734-
if quality > 100:
7735-
quality = 100
7736-
if quality < 0:
7737-
quality = 0
7738-
7739-
return quality
7699+
return max(min(quality, 100), 0)
77407700

77417701
def get_access_point_timeout(self):
77427702
"""
@@ -10112,7 +10072,7 @@ def _prepare_network_discovery(self):
1011210072
self.set_discovery_timeout(self._node_timeout)
1011310073
except XBeeException as exc:
1011410074
raise XBeeException(
10115-
"Could not prepare XBee for network discovery: %s" % str(exc))
10075+
"Could not prepare XBee for network discovery: %s" % str(exc)) from exc
1011610076

1011710077
def __init_scan(self):
1011810078
"""
@@ -10346,6 +10306,7 @@ def __discover_devices(self, node_id=None):
1034610306
return err_code
1034710307
except Exception as exc:
1034810308
self._local_xbee.log.exception(exc)
10309+
return NetworkDiscoveryStatus.ERROR_GENERAL
1034910310

1035010311
def _node_discovery_process_finished(self, requester, code=None, error=None):
1035110312
"""
@@ -10713,7 +10674,7 @@ def get_node_connections(self, node):
1071310674
connections = []
1071410675
with self.__conn_lock:
1071510676
for conn in self.__connections:
10716-
if conn.node_a == node or conn.node_b == node:
10677+
if node in (conn.node_a, conn.node_b):
1071710678
connections.append(conn)
1071810679

1071910680
return connections
@@ -11074,7 +11035,7 @@ def _prepare_network_discovery(self):
1107411035
self.__enable_explicit_mode()
1107511036
except XBeeException as exc:
1107611037
raise XBeeException(
11077-
"Could not prepare XBee for network discovery: %s" % str(exc))
11038+
"Could not prepare XBee for network discovery: %s" % str(exc)) from exc
1107811039

1107911040
def _discover_neighbors(self, requester, nodes_queue, active_processes, node_timeout):
1108011041
"""
@@ -11457,7 +11418,8 @@ def __get_zdo_command(self, xbee, cmd_type):
1145711418

1145811419
return None
1145911420

11460-
def __stop_zdo_command(self, commands, cmd_type):
11421+
@staticmethod
11422+
def __stop_zdo_command(commands, cmd_type):
1146111423
"""
1146211424
Stops the execution of the ZDO command contained in the given dictionary.
1146311425
This method blocks until the ZDO command is completely stopped.
@@ -11609,7 +11571,7 @@ def _prepare_network_discovery(self):
1160911571

1161011572
except XBeeException as exc:
1161111573
raise XBeeException(
11612-
"Could not prepare XBee for network discovery: %s" % str(exc))
11574+
"Could not prepare XBee for network discovery: %s" % str(exc)) from exc
1161311575

1161411576
# Calculate the real timeout to wait for responses, based on 'N?' and
1161511577
# the cyclic sleep times, if the node is configured for that.

digi/xbee/filesystem.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ def get(cls, name):
148148
provided name.
149149
"""
150150
for value in _FilesystemFunction:
151-
if value.name == name:
151+
if value.cmd_name == name:
152152
return value
153153

154154
return None
155155

156156
@property
157-
def name(self):
157+
def cmd_name(self):
158158
"""
159159
Returns the name of the `_FilesystemFunction` element.
160160
@@ -2684,7 +2684,7 @@ def _is_function_supported(self, function):
26842684
if not isinstance(function, _FilesystemFunction):
26852685
return False
26862686

2687-
return function.name in self._supported_functions
2687+
return function.cmd_name in self._supported_functions
26882688

26892689
@staticmethod
26902690
def _check_function_error(answer, command):
@@ -2777,7 +2777,7 @@ def _execute_command(self, cmd_type, *args, wait_for_answer=True):
27772777
"""
27782778
# Sanity checks.
27792779
if not self._is_function_supported(cmd_type):
2780-
raise FileSystemException(_ERROR_FUNCTION_NOT_SUPPORTED % cmd_type.name)
2780+
raise FileSystemException(_ERROR_FUNCTION_NOT_SUPPORTED % cmd_type.cmd_name)
27812781
if not self._check_atcmd_mode():
27822782
raise FileSystemException(_ERROR_ENTER_CMD_MODE)
27832783

@@ -2794,7 +2794,7 @@ def _execute_command(self, cmd_type, *args, wait_for_answer=True):
27942794
return answer
27952795
except SerialException as exc:
27962796
raise FileSystemException(_ERROR_EXECUTE_COMMAND %
2797-
(command.replace("\r", ""), str(exc)))
2797+
(command.replace("\r", ""), str(exc))) from None
27982798

27992799
@property
28002800
def is_connected(self):
@@ -2849,7 +2849,7 @@ def connect(self):
28492849
# much info but confusion.
28502850
pass
28512851
if isinstance(exc, SerialException):
2852-
raise FileSystemException(_ERROR_CONNECT_FILESYSTEM % str(exc))
2852+
raise FileSystemException(_ERROR_CONNECT_FILESYSTEM % str(exc)) from None
28532853
raise exc
28542854

28552855
def disconnect(self):
@@ -3071,10 +3071,10 @@ def put_file(self, source_path, dest_path, secure=False, progress_callback=None)
30713071
# Sanity checks.
30723072
if secure and not self._is_function_supported(_FilesystemFunction.XPUT):
30733073
raise FileSystemException(_ERROR_FUNCTION_NOT_SUPPORTED
3074-
% _FilesystemFunction.XPUT.name)
3074+
% _FilesystemFunction.XPUT.cmd_name)
30753075
if not secure and not self._is_function_supported(_FilesystemFunction.PUT):
30763076
raise FileSystemException(_ERROR_FUNCTION_NOT_SUPPORTED
3077-
% _FilesystemFunction.PUT.name)
3077+
% _FilesystemFunction.PUT.cmd_name)
30783078

30793079
# Sanitize destination path.
30803080
dest_path = dest_path.replace('\\', '/')
@@ -3111,7 +3111,7 @@ def put_file(self, source_path, dest_path, secure=False, progress_callback=None)
31113111
progress_cb=progress_callback, log=_log)
31123112
except XModemException as exc:
31133113
raise FileSystemException(_ERROR_EXECUTE_COMMAND %
3114-
(command.replace("\r", ""), str(exc)))
3114+
(command.replace("\r", ""), str(exc))) from None
31153115
# Read operation result.
31163116
answer = self._read_data(timeout=_READ_DATA_TIMEOUT,
31173117
empty_retries=_READ_EMPTY_DATA_RETRIES)
@@ -3197,14 +3197,14 @@ def get_file(self, source_path, dest_path, progress_callback=None):
31973197
"Transfer not ready"))
31983198
except SerialException as exc:
31993199
raise FileSystemException(_ERROR_EXECUTE_COMMAND %
3200-
(command.replace("\r", ""), str(exc)))
3200+
(command.replace("\r", ""), str(exc))) from None
32013201
# Receive the file.
32023202
try:
32033203
xmodem.get_file_ymodem(dest_path, self._xmodem_write_cb, self._xmodem_read_cb,
32043204
progress_cb=progress_callback, log=_log)
32053205
except XModemException as exc:
32063206
raise FileSystemException(_ERROR_EXECUTE_COMMAND %
3207-
(command.replace("\r", ""), str(exc)))
3207+
(command.replace("\r", ""), str(exc))) from None
32083208
# Read operation result.
32093209
answer = self._read_data()
32103210
if not answer:
@@ -3233,7 +3233,7 @@ def format_filesystem(self):
32333233
raise FileSystemException(_ERROR_TIMEOUT)
32343234
except SerialException as exc:
32353235
raise FileSystemException(_ERROR_EXECUTE_COMMAND %
3236-
(command.replace("\r", ""), str(exc)))
3236+
(command.replace("\r", ""), str(exc))) from None
32373237

32383238
def get_usage_information(self):
32393239
"""
@@ -3323,7 +3323,7 @@ def update_remote_filesystem_image(remote_device, ota_filesystem_file,
33233323
timeout=timeout, progress_callback=progress_callback, _prepare=_prepare)
33243324
except FirmwareUpdateException as exc:
33253325
_log.error("ERROR: %s", str(exc))
3326-
raise FileSystemException(str(exc))
3326+
raise FileSystemException(str(exc)) from None
33273327

33283328

33293329
def check_fs_support(xbee, min_fw_vers=None, max_fw_vers=None):

0 commit comments

Comments
 (0)