Skip to content

Commit

Permalink
Manually fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
MattHag committed Feb 20, 2024
1 parent 8e23146 commit 20319aa
Show file tree
Hide file tree
Showing 15 changed files with 213 additions and 182 deletions.
5 changes: 4 additions & 1 deletion lib/hidapi/hidconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@
prompt = "?? Input: " if interactive else ""
start_time = time.time()

strhex = lambda d: hexlify(d).decode("ascii").upper()

def strhex(d):
return hexlify(d).decode("ascii").upper()


#
#
Expand Down
21 changes: 10 additions & 11 deletions lib/logitech_receiver/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,14 @@
#
#

_wired_device = lambda product_id, interface: {
"vendor_id": 0x046D,
"product_id": product_id,
"bus_id": 0x3,
"usb_interface": interface,
"isDevice": True,
}

_bt_device = lambda product_id: {"vendor_id": 0x046D, "product_id": product_id, "bus_id": 0x5, "isDevice": True}
def _wired_device(product_id, interface):
return {"vendor_id": 1133, "product_id": product_id, "bus_id": 3, "usb_interface": interface, "isDevice": True}


def _bt_device(product_id):
return {"vendor_id": 1133, "product_id": product_id, "bus_id": 5, "isDevice": True}


DEVICE_IDS = []

Expand Down Expand Up @@ -243,7 +242,7 @@ def write(handle, devnumber, data, long_message=False):
except Exception as reason:
logger.error("write failed, assuming handle %r no longer available", handle)
close(handle)
raise exceptions.NoReceiver(reason=reason)
raise exceptions.NoReceiver(reason=reason) from reason


def read(handle, timeout=DEFAULT_TIMEOUT):
Expand Down Expand Up @@ -292,7 +291,7 @@ def _read(handle, timeout):
except Exception as reason:
logger.warning("read failed, assuming handle %r no longer available", handle)
close(handle)
raise exceptions.NoReceiver(reason=reason)
raise exceptions.NoReceiver(reason=reason) from reason

if data and check_message(data): # ignore messages that fail check
report_id = ord(data[:1])
Expand Down Expand Up @@ -324,7 +323,7 @@ def _skip_incoming(handle, ihandle, notifications_hook):
except Exception as reason:
logger.error("read failed, assuming receiver %s no longer available", handle)
close(handle)
raise exceptions.NoReceiver(reason=reason)
raise exceptions.NoReceiver(reason=reason) from reason

if data:
if check_message(data): # only process messages that pass check
Expand Down
221 changes: 119 additions & 102 deletions lib/logitech_receiver/base_usb.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,106 +35,125 @@
# re_pairs determines whether a receiver pairs by replacing existing pairings, default to False
## currently only one receiver is so marked - should there be more?

_DRIVER = ("hid-generic", "generic-usb", "logitech-djreceiver")

_bolt_receiver = lambda product_id: {
"vendor_id": 0x046D,
"product_id": product_id,
"usb_interface": 2,
"hid_driver": _DRIVER, # noqa: F821
"name": _("Bolt Receiver"),
"receiver_kind": "bolt",
"max_devices": 6,
"may_unpair": True,
}

_unifying_receiver = lambda product_id: {
"vendor_id": 0x046D,
"product_id": product_id,
"usb_interface": 2,
"hid_driver": _DRIVER, # noqa: F821
"name": _("Unifying Receiver"),
"receiver_kind": "unifying",
"may_unpair": True,
}

_nano_receiver = lambda product_id: {
"vendor_id": 0x046D,
"product_id": product_id,
"usb_interface": 1,
"hid_driver": _DRIVER, # noqa: F821
"name": _("Nano Receiver"),
"receiver_kind": "nano",
"may_unpair": False,
"re_pairs": True,
}

_nano_receiver_no_unpair = lambda product_id: {
"vendor_id": 0x046D,
"product_id": product_id,
"usb_interface": 1,
"hid_driver": _DRIVER, # noqa: F821
"name": _("Nano Receiver"),
"receiver_kind": "nano",
"may_unpair": False,
"unpair": False,
"re_pairs": True,
}

_nano_receiver_max2 = lambda product_id: {
"vendor_id": 0x046D,
"product_id": product_id,
"usb_interface": 1,
"hid_driver": _DRIVER, # noqa: F821
"name": _("Nano Receiver"),
"receiver_kind": "nano",
"max_devices": 2,
"may_unpair": False,
"re_pairs": True,
}

_nano_receiver_maxn = lambda product_id, max: {
"vendor_id": 0x046D,
"product_id": product_id,
"usb_interface": 1,
"hid_driver": _DRIVER, # noqa: F821
"name": _("Nano Receiver"),
"receiver_kind": "nano",
"max_devices": max,
"may_unpair": False,
"re_pairs": True,
}

_lenovo_receiver = lambda product_id: {
"vendor_id": 0x17EF,
"product_id": product_id,
"usb_interface": 1,
"hid_driver": _DRIVER, # noqa: F821
"name": _("Nano Receiver"),
"receiver_kind": "nano",
"may_unpair": False,
}

_lightspeed_receiver = lambda product_id: {
"vendor_id": 0x046D,
"product_id": product_id,
"usb_interface": 2,
"hid_driver": _DRIVER, # noqa: F821
"name": _("Lightspeed Receiver"),
"may_unpair": False,
}

_ex100_receiver = lambda product_id: {
"vendor_id": 0x046D,
"product_id": product_id,
"usb_interface": 1,
"hid_driver": _DRIVER, # noqa: F821
"name": _("EX100 Receiver 27 Mhz"),
"receiver_kind": "27Mhz",
"max_devices": 4,
"may_unpair": False,
"re_pairs": True,
}
DRIVER = ("hid-generic", "generic-usb", "logitech-djreceiver")


def _bolt_receiver(product_id):
return {
"vendor_id": 1133,
"product_id": product_id,
"usb_interface": 2,
"hid_driver": DRIVER,
"name": _("Bolt Receiver"),
"receiver_kind": "bolt",
"max_devices": 6,
"may_unpair": True,
}


def _unifying_receiver(product_id):
return {
"vendor_id": 1133,
"product_id": product_id,
"usb_interface": 2,
"hid_driver": DRIVER,
"name": _("Unifying Receiver"),
"receiver_kind": "unifying",
"may_unpair": True,
}


def _nano_receiver(product_id):
return {
"vendor_id": 1133,
"product_id": product_id,
"usb_interface": 1,
"hid_driver": DRIVER,
"name": _("Nano Receiver"),
"receiver_kind": "nano",
"may_unpair": False,
"re_pairs": True,
}


def _nano_receiver_no_unpair(product_id):
return {
"vendor_id": 1133,
"product_id": product_id,
"usb_interface": 1,
"hid_driver": DRIVER,
"name": _("Nano Receiver"),
"receiver_kind": "nano",
"may_unpair": False,
"unpair": False,
"re_pairs": True,
}


def _nano_receiver_max2(product_id):
return {
"vendor_id": 1133,
"product_id": product_id,
"usb_interface": 1,
"hid_driver": DRIVER,
"name": _("Nano Receiver"),
"receiver_kind": "nano",
"max_devices": 2,
"may_unpair": False,
"re_pairs": True,
}


def _nano_receiver_maxn(product_id, max):
return {
"vendor_id": 1133,
"product_id": product_id,
"usb_interface": 1,
"hid_driver": DRIVER,
"name": _("Nano Receiver"),
"receiver_kind": "nano",
"max_devices": max,
"may_unpair": False,
"re_pairs": True,
}


def _lenovo_receiver(product_id):
return {
"vendor_id": 6127,
"product_id": product_id,
"usb_interface": 1,
"hid_driver": DRIVER,
"name": _("Nano Receiver"),
"receiver_kind": "nano",
"may_unpair": False,
}


def _lightspeed_receiver(product_id):
return {
"vendor_id": 1133,
"product_id": product_id,
"usb_interface": 2,
"hid_driver": DRIVER,
"name": _("Lightspeed Receiver"),
"may_unpair": False,
}


def _ex100_receiver(product_id):
return {
"vendor_id": 1133,
"product_id": product_id,
"usb_interface": 1,
"hid_driver": DRIVER,
"name": _("EX100 Receiver 27 Mhz"),
"receiver_kind": "27Mhz",
"max_devices": 4,
"may_unpair": False,
"re_pairs": True,
}


# Receivers added here should also be listed in
# share/solaar/io.github.pwr_solaar.solaar.metainfo.xml
Expand Down Expand Up @@ -204,5 +223,3 @@
LIGHTSPEED_RECEIVER_C547,
EX100_27MHZ_RECEIVER_C517,
)

del _DRIVER, _unifying_receiver, _nano_receiver, _lenovo_receiver, _lightspeed_receiver
5 changes: 4 additions & 1 deletion lib/logitech_receiver/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@

import yaml as _yaml

is_string = lambda d: isinstance(d, str)

def is_string(d):
return isinstance(d, str)


#
#
Expand Down
16 changes: 0 additions & 16 deletions lib/logitech_receiver/diversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -1416,22 +1416,6 @@ def data(self):
{"Rule": [{"Key": ["Brightness Up", "pressed"]}, {"KeyPress": "XF86_MonBrightnessUp"}]},
]
},
# {'Rule': [ # In firefox, crown emits keys that move up and down if not pressed, rotate through tabs otherwise
# {'Process': 'firefox'},
# {'Rule': [{'Test': 'crown_pressed'}, {'Test': 'crown_right_ratchet'}, {'KeyPress': ['Control_R', 'Tab']}]},
# {'Rule': [{'Test': 'crown_pressed'},
# {'Test': 'crown_left_ratchet'},
# {'KeyPress': ['Control_R', 'Shift_R', 'Tab']}]},
# {'Rule': [{'Test': 'crown_right_ratchet'}, {'KeyPress': 'Down'}]},
# {'Rule': [{'Test': 'crown_left_ratchet'}, {'KeyPress': 'Up'}]},
# ]},
# {'Rule': [ # Otherwise, crown movements emit keys that modify volume if not pressed, move between tracks otherwise
# {'Feature': 'CROWN'}, {'Report': 0x0},
# {'Rule': [{'Test': 'crown_pressed'}, {'Test': 'crown_right_ratchet'}, {'KeyPress': 'XF86_AudioNext'}]},
# {'Rule': [{'Test': 'crown_pressed'}, {'Test': 'crown_left_ratchet'}, {'KeyPress': 'XF86_AudioPrev'}]},
# {'Rule': [{'Test': 'crown_right_ratchet'}, {'KeyPress': 'XF86_AudioRaiseVolume'}]},
# {'Rule': [{'Test': 'crown_left_ratchet'}, {'KeyPress': 'XF86_AudioLowerVolume'}]}
# ]},
]
)

Expand Down
33 changes: 19 additions & 14 deletions lib/logitech_receiver/hidpp20.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ def __getitem__(self, feature: _NamedInt) -> Optional[int]:
return index if index else False

def __setitem__(self, feature, index):
if type(super().get(feature)) == int:
if isinstance(super().get(feature), int):
self.inverse.pop(super().get(feature))
super().__setitem__(feature, index)
if type(index) == int:
if isinstance(index, int):
self.inverse[index] = feature

def __delitem__(self, feature):
Expand Down Expand Up @@ -902,19 +902,24 @@ class LEDParam:

LEDRampChoices = _NamedInts(default=0, yes=1, no=2)
LEDFormChoices = _NamedInts(default=0, sine=1, square=2, triangle=3, sawtooth=4, sharkfin=5, exponential=6)
LEDParamSize = {LEDParam.color: 3, LEDParam.speed: 1, LEDParam.period: 2,
LEDParam.intensity: 1, LEDParam.ramp: 1, LEDParam.form: 1} # yapf: disable
LEDParamSize = {
LEDParam.color: 3,
LEDParam.speed: 1,
LEDParam.period: 2,
LEDParam.intensity: 1,
LEDParam.ramp: 1,
LEDParam.form: 1,
}
LEDEffects = { # Wave=0x04, Stars=0x05, Press=0x06, Audio=0x07, # not implemented
0x0: [_NamedInt(0x0, _('Disabled')), {}],
0x1: [_NamedInt(0x1, _('Static')), {LEDParam.color: 0, LEDParam.ramp: 3}],
0x2: [_NamedInt(0x2, _('Pulse')), {LEDParam.color: 0, LEDParam.speed: 3}],
0x3: [_NamedInt(0x3, _('Cycle')), {LEDParam.period: 5, LEDParam.intensity: 7}],
0x8: [_NamedInt(0x8, _('Boot')), {}],
0x9: [_NamedInt(0x9, _('Demo')), {}],
0xA: [_NamedInt(0xA, _('Breathe')), {LEDParam.color: 0, LEDParam.period: 3,
LEDParam.form: 5, LEDParam.intensity: 6}],
0xB: [_NamedInt(0xB, _('Ripple')), {LEDParam.color: 0, LEDParam.period: 4}]
} # yapf: disable
0x0: [_NamedInt(0x0, _("Disabled")), {}],
0x1: [_NamedInt(0x1, _("Static")), {LEDParam.color: 0, LEDParam.ramp: 3}],
0x2: [_NamedInt(0x2, _("Pulse")), {LEDParam.color: 0, LEDParam.speed: 3}],
0x3: [_NamedInt(0x3, _("Cycle")), {LEDParam.period: 5, LEDParam.intensity: 7}],
0x8: [_NamedInt(0x8, _("Boot")), {}],
0x9: [_NamedInt(0x9, _("Demo")), {}],
0xA: [_NamedInt(0xA, _("Breathe")), {LEDParam.color: 0, LEDParam.period: 3, LEDParam.form: 5, LEDParam.intensity: 6}],
0xB: [_NamedInt(0xB, _("Ripple")), {LEDParam.color: 0, LEDParam.period: 4}],
}


class LEDEffectSetting: # an effect plus its parameters
Expand Down
12 changes: 9 additions & 3 deletions lib/logitech_receiver/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ def device_icon_name(name, kind=None):
return n

else:
init = lambda: False
uninit = lambda: None
show = lambda dev, reason=None: None

def init():
return False

def uninit():
return None

def show(dev, reason=None):
return None
Loading

0 comments on commit 20319aa

Please sign in to comment.