From 476f41f8ae48a3f0b870d1c9e2d08d4d5cbb99f0 Mon Sep 17 00:00:00 2001 From: "Peter F. Patel-Schneider" Date: Tue, 20 Feb 2024 05:49:47 -0500 Subject: [PATCH] logitech_receiver: style fixes --- lib/logitech_receiver/base.py | 3 ++- lib/logitech_receiver/hidpp20.py | 15 ++++++++------- lib/solaar/cli/show.py | 3 ++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/logitech_receiver/base.py b/lib/logitech_receiver/base.py index 24234e7d90..2f06cf78b0 100644 --- a/lib/logitech_receiver/base.py +++ b/lib/logitech_receiver/base.py @@ -554,7 +554,8 @@ def ping(handle, devnumber, long_message=False): error = ord(reply_data[3:4]) if error == _hidpp10_constants.ERROR.invalid_SubID__command: # a valid reply from a HID++ 1.0 device return 1.0 - if error == _hidpp10_constants.ERROR.resource_error or error == _hidpp10_constants.ERROR.connection_request_failed: + if error == _hidpp10_constants.ERROR.resource_error or \ + error == _hidpp10_constants.ERROR.connection_request_failed: return # device unreachable if error == _hidpp10_constants.ERROR.unknown_device: # no paired device with that number logger.error('(%s) device %d error on ping request: unknown device', handle, devnumber) diff --git a/lib/logitech_receiver/hidpp20.py b/lib/logitech_receiver/hidpp20.py index 919557bc56..c95c082f4a 100644 --- a/lib/logitech_receiver/hidpp20.py +++ b/lib/logitech_receiver/hidpp20.py @@ -37,8 +37,9 @@ from .common import bytes2int as _bytes2int from .common import crc16 as _crc16 from .common import int2bytes as _int2bytes -from .hidpp20_constants import (BATTERY_STATUS, CHARGE_LEVEL, CHARGE_STATUS, CHARGE_TYPE, DEVICE_KIND, ERROR, FEATURE, - FIRMWARE_KIND, GESTURE) +from .hidpp20_constants import BATTERY_STATUS, CHARGE_LEVEL, CHARGE_STATUS, CHARGE_TYPE, DEVICE_KIND, ERROR, FEATURE +from .hidpp20_constants import FIRMWARE_KIND as _FIRMWARE_KIND +from .hidpp20_constants import GESTURE from .i18n import _ logger = logging.getLogger(__name__) @@ -276,7 +277,7 @@ def _getCidReporting(self): self._mapping_flags = mapping_flags_1 | (mapping_flags_2 << 8) else: raise exceptions.FeatureCallError(msg='No reply from device.') - except exceptions.FeatureCallError: # if the key hasn't ever been configured then the read may fail so only produce a warning + except exceptions.FeatureCallError: # if the key hasn't ever been configured only produce a warning if logger.isEnabledFor(logging.WARNING): logger.warn( f'Feature Call Error in _getCidReporting on device {self._device} for cid {self._cid} - use defaults' @@ -1381,11 +1382,11 @@ def get_firmware(device): if build: version += '.B%04X' % build extras = fw_info[9:].rstrip(b'\x00') or None - fw_info = _FirmwareInfo(FIRMWARE_KIND[level], name.decode('ascii'), version, extras) - elif level == FIRMWARE_KIND.Hardware: - fw_info = _FirmwareInfo(FIRMWARE_KIND.Hardware, '', str(ord(fw_info[1:2])), None) + fw_info = _FirmwareInfo(_FIRMWARE_KIND[level], name.decode('ascii'), version, extras) + elif level == _FIRMWARE_KIND.Hardware: + fw_info = _FirmwareInfo(_FIRMWARE_KIND.Hardware, '', str(ord(fw_info[1:2])), None) else: - fw_info = _FirmwareInfo(FIRMWARE_KIND.Other, '', '', None) + fw_info = _FirmwareInfo(_FIRMWARE_KIND.Other, '', '', None) fw.append(fw_info) # if logger.isEnabledFor(logging.DEBUG): diff --git a/lib/solaar/cli/show.py b/lib/solaar/cli/show.py index 5500e1e783..c69e91d41b 100644 --- a/lib/solaar/cli/show.py +++ b/lib/solaar/cli/show.py @@ -222,7 +222,8 @@ def _print_device(dev, num=None): if ids: unitId, modelId, tid_map = ids print(' Unit ID: %s Model ID: %s Transport IDs: %s' % (unitId, modelId, tid_map)) - elif feature == _hidpp20_constants.FEATURE.REPORT_RATE or feature == _hidpp20_constants.FEATURE.EXTENDED_ADJUSTABLE_REPORT_RATE: + elif feature == _hidpp20_constants.FEATURE.REPORT_RATE or \ + feature == _hidpp20_constants.FEATURE.EXTENDED_ADJUSTABLE_REPORT_RATE: print(' Report Rate: %s' % _hidpp20.get_polling_rate(dev)) elif feature == _hidpp20_constants.FEATURE.REMAINING_PAIRING: print(' Remaining Pairings: %d' % _hidpp20.get_remaining_pairing(dev))