logitech_receiver: style fixes

This commit is contained in:
Peter F. Patel-Schneider 2024-02-20 05:49:47 -05:00
parent 5f487dd3b2
commit 476f41f8ae
3 changed files with 12 additions and 9 deletions

View File

@ -554,7 +554,8 @@ def ping(handle, devnumber, long_message=False):
error = ord(reply_data[3:4]) error = ord(reply_data[3:4])
if error == _hidpp10_constants.ERROR.invalid_SubID__command: # a valid reply from a HID++ 1.0 device if error == _hidpp10_constants.ERROR.invalid_SubID__command: # a valid reply from a HID++ 1.0 device
return 1.0 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 return # device unreachable
if error == _hidpp10_constants.ERROR.unknown_device: # no paired device with that number 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) logger.error('(%s) device %d error on ping request: unknown device', handle, devnumber)

View File

@ -37,8 +37,9 @@ from .common import UnsortedNamedInts as _UnsortedNamedInts
from .common import bytes2int as _bytes2int from .common import bytes2int as _bytes2int
from .common import crc16 as _crc16 from .common import crc16 as _crc16
from .common import int2bytes as _int2bytes from .common import int2bytes as _int2bytes
from .hidpp20_constants import (BATTERY_STATUS, CHARGE_LEVEL, CHARGE_STATUS, CHARGE_TYPE, DEVICE_KIND, ERROR, FEATURE, from .hidpp20_constants import BATTERY_STATUS, CHARGE_LEVEL, CHARGE_STATUS, CHARGE_TYPE, DEVICE_KIND, ERROR, FEATURE
FIRMWARE_KIND, GESTURE) from .hidpp20_constants import FIRMWARE_KIND as _FIRMWARE_KIND
from .hidpp20_constants import GESTURE
from .i18n import _ from .i18n import _
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -276,7 +277,7 @@ class ReprogrammableKeyV4(ReprogrammableKey):
self._mapping_flags = mapping_flags_1 | (mapping_flags_2 << 8) self._mapping_flags = mapping_flags_1 | (mapping_flags_2 << 8)
else: else:
raise exceptions.FeatureCallError(msg='No reply from device.') 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): if logger.isEnabledFor(logging.WARNING):
logger.warn( logger.warn(
f'Feature Call Error in _getCidReporting on device {self._device} for cid {self._cid} - use defaults' 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: if build:
version += '.B%04X' % build version += '.B%04X' % build
extras = fw_info[9:].rstrip(b'\x00') or None extras = fw_info[9:].rstrip(b'\x00') or None
fw_info = _FirmwareInfo(FIRMWARE_KIND[level], name.decode('ascii'), version, extras) fw_info = _FirmwareInfo(_FIRMWARE_KIND[level], name.decode('ascii'), version, extras)
elif level == FIRMWARE_KIND.Hardware: elif level == _FIRMWARE_KIND.Hardware:
fw_info = _FirmwareInfo(FIRMWARE_KIND.Hardware, '', str(ord(fw_info[1:2])), None) fw_info = _FirmwareInfo(_FIRMWARE_KIND.Hardware, '', str(ord(fw_info[1:2])), None)
else: else:
fw_info = _FirmwareInfo(FIRMWARE_KIND.Other, '', '', None) fw_info = _FirmwareInfo(_FIRMWARE_KIND.Other, '', '', None)
fw.append(fw_info) fw.append(fw_info)
# if logger.isEnabledFor(logging.DEBUG): # if logger.isEnabledFor(logging.DEBUG):

View File

@ -222,7 +222,8 @@ def _print_device(dev, num=None):
if ids: if ids:
unitId, modelId, tid_map = ids unitId, modelId, tid_map = ids
print(' Unit ID: %s Model ID: %s Transport IDs: %s' % (unitId, modelId, tid_map)) 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)) print(' Report Rate: %s' % _hidpp20.get_polling_rate(dev))
elif feature == _hidpp20_constants.FEATURE.REMAINING_PAIRING: elif feature == _hidpp20_constants.FEATURE.REMAINING_PAIRING:
print(' Remaining Pairings: %d' % _hidpp20.get_remaining_pairing(dev)) print(' Remaining Pairings: %d' % _hidpp20.get_remaining_pairing(dev))