From fbd5557cb5d51150f85b2556b140fc098fed89be Mon Sep 17 00:00:00 2001 From: DomHeadroom Date: Sun, 1 Sep 2024 12:19:49 +0200 Subject: [PATCH 1/3] Rewrote string concatenation/format with f strings --- lib/hidapi/hidconsole.py | 6 ++-- lib/keysyms/generate.py | 6 ++-- lib/logitech_receiver/common.py | 4 +-- lib/logitech_receiver/device.py | 4 +-- lib/logitech_receiver/diversion.py | 34 +++++++++---------- lib/logitech_receiver/hidpp10.py | 2 +- lib/logitech_receiver/hidpp20.py | 22 ++++++------ lib/logitech_receiver/listener.py | 2 +- lib/logitech_receiver/notifications.py | 2 +- lib/logitech_receiver/notify.py | 2 +- lib/logitech_receiver/receiver.py | 2 +- lib/logitech_receiver/settings.py | 4 +-- lib/logitech_receiver/settings_templates.py | 8 ++--- lib/logitech_receiver/special_keys.py | 4 +-- lib/solaar/cli/probe.py | 16 ++++----- lib/solaar/cli/show.py | 4 +-- lib/solaar/cli/unpair.py | 3 +- lib/solaar/gtk.py | 6 ++-- lib/solaar/i18n.py | 2 +- lib/solaar/ui/config_panel.py | 8 ++--- lib/solaar/ui/icons.py | 2 +- lib/solaar/ui/rule_actions.py | 2 +- lib/solaar/ui/rule_conditions.py | 2 +- lib/solaar/ui/window.py | 10 +++--- .../logitech_receiver/test_hidpp20_complex.py | 4 +-- 25 files changed, 80 insertions(+), 81 deletions(-) diff --git a/lib/hidapi/hidconsole.py b/lib/hidapi/hidconsole.py index e418e9457..a861e5bba 100644 --- a/lib/hidapi/hidconsole.py +++ b/lib/hidapi/hidconsole.py @@ -46,7 +46,7 @@ def strhex(d): def _print(marker, data, scroll=False): t = time.time() - start_time if isinstance(data, str): - s = marker + " " + data + s = f"{marker} {data}" else: hexs = strhex(data) s = "%s (% 8.3f) [%s %s %s %s] %s" % (marker, t, hexs[0:2], hexs[2:4], hexs[4:8], hexs[8:], repr(data)) @@ -86,7 +86,7 @@ def _continuous_read(handle, timeout=2000): try: reply = hidapi.read(handle, 128, timeout) except OSError as e: - _error("Read failed, aborting: " + str(e), True) + _error(f"Read failed, aborting: {str(e)}", True) break assert reply is not None if reply: @@ -97,7 +97,7 @@ def _validate_input(line, hidpp=False): try: data = unhexlify(line.encode("ascii")) except Exception as e: - _error("Invalid input: " + str(e)) + _error(f"Invalid input: {str(e)}") return None if hidpp: diff --git a/lib/keysyms/generate.py b/lib/keysyms/generate.py index 5368f0c7c..4171f1f60 100755 --- a/lib/keysyms/generate.py +++ b/lib/keysyms/generate.py @@ -30,9 +30,9 @@ def main(): for name, sym, uni in findall(xf86pattern, text): sym = int(sym, 16) uni = int(uni, 16) if uni else None - if keysymdef.get("XF86_" + name, None): - print("KEY DUP", "XF86_" + name) - keysymdef["XF86_" + name] = sym + if keysymdef.get(f"XF86_{name}", None): + print("KEY DUP", f"XF86_{name}") + keysymdef[f"XF86_{name}"] = sym with open("keysymdef.py", "w") as f: f.write("# flake8: noqa\nkeysymdef = \\\n") diff --git a/lib/logitech_receiver/common.py b/lib/logitech_receiver/common.py index 7905f4973..d35b4b6ed 100644 --- a/lib/logitech_receiver/common.py +++ b/lib/logitech_receiver/common.py @@ -326,7 +326,7 @@ def __eq__(self, other): return self.name.lower() == other.lower() # this should catch comparisons with bytes in Py3 if other is not None: - raise TypeError("Unsupported type " + str(type(other))) + raise TypeError(f"Unsupported type {str(type(other))}") def __ne__(self, other): return not self.__eq__(other) @@ -460,7 +460,7 @@ def __getitem__(self, index): def __setitem__(self, index, name): assert isinstance(index, int), type(index) if isinstance(name, NamedInt): - assert int(index) == int(name), repr(index) + " " + repr(name) + assert int(index) == int(name), f"{repr(index)} {repr(name)}" value = name elif isinstance(name, str): value = NamedInt(index, name) diff --git a/lib/logitech_receiver/device.py b/lib/logitech_receiver/device.py index a627e6fc5..f2315b449 100644 --- a/lib/logitech_receiver/device.py +++ b/lib/logitech_receiver/device.py @@ -225,14 +225,14 @@ def codename(self): self._codename = codename elif self.protocol < 2.0: self._codename = "? (%s)" % (self.wpid or self.product_id) - return self._codename or "?? (%s)" % (self.wpid or self.product_id) + return self._codename or f"?? ({self.wpid or self.product_id})" @property def name(self): if not self._name: if self.online and self.protocol >= 2.0: self._name = _hidpp20.get_name(self) - return self._name or self._codename or "Unknown device %s" % (self.wpid or self.product_id) + return self._name or self._codename or f"Unknown device {self.wpid or self.product_id}" def get_ids(self): ids = _hidpp20.get_ids(self) diff --git a/lib/logitech_receiver/diversion.py b/lib/logitech_receiver/diversion.py index 78acbb6a7..900c8dd4a 100644 --- a/lib/logitech_receiver/diversion.py +++ b/lib/logitech_receiver/diversion.py @@ -509,7 +509,7 @@ def __init__(self, args, source=None, warn=True): self.source = source def __str__(self): - source = "(" + self.source + ")" if self.source else "" + source = f"({self.source})" if self.source else "" return f"Rule{source}[{', '.join([c.__str__() for c in self.components])}]" def evaluate(self, feature, notification, device, last_result): @@ -553,7 +553,7 @@ def __init__(self, op, warn=True): self.component = self.compile(op) def __str__(self): - return "Not: " + str(self.component) + return f"Not: {str(self.component)}" def evaluate(self, feature, notification, device, last_result): if logger.isEnabledFor(logging.DEBUG): @@ -672,7 +672,7 @@ def __init__(self, process, warn=True): self.process = str(process) def __str__(self): - return "Process: " + str(self.process) + return f"Process: {str(self.process)}" def evaluate(self, feature, notification, device, last_result): if logger.isEnabledFor(logging.DEBUG): @@ -703,7 +703,7 @@ def __init__(self, process, warn=True): self.process = str(process) def __str__(self): - return "MouseProcess: " + str(self.process) + return f"MouseProcess: {str(self.process)}" def evaluate(self, feature, notification, device, last_result): if logger.isEnabledFor(logging.DEBUG): @@ -727,7 +727,7 @@ def __init__(self, feature, warn=True): self.feature = FEATURE[feature] def __str__(self): - return "Feature: " + str(self.feature) + return f"Feature: {str(self.feature)}" def evaluate(self, feature, notification, device, last_result): if logger.isEnabledFor(logging.DEBUG): @@ -748,7 +748,7 @@ def __init__(self, report, warn=True): self.report = report def __str__(self): - return "Report: " + str(self.report) + return f"Report: {str(self.report)}" def evaluate(self, report, notification, device, last_result): if logger.isEnabledFor(logging.DEBUG): @@ -821,7 +821,7 @@ def __init__(self, modifiers, warn=True): logger.warning("unknown rule Modifier value: %s", k) def __str__(self): - return "Modifiers: " + str(self.desired) + return f"Modifiers: {str(self.desired)}" def evaluate(self, feature, notification, device, last_result): if logger.isEnabledFor(logging.DEBUG): @@ -967,7 +967,7 @@ def __init__(self, test, warn=True): logger.warning("rule Test argument not valid %s", test) def __str__(self): - return "Test: " + str(self.test) + return f"Test: {str(self.test)}" def evaluate(self, feature, notification, device, last_result): if logger.isEnabledFor(logging.DEBUG): @@ -995,7 +995,7 @@ def __init__(self, test, warn=True): logger.warning("rule TestBytes argument not valid %s", test) def __str__(self): - return "TestBytes: " + str(self.test) + return f"TestBytes: {str(self.test)}" def evaluate(self, feature, notification, device, last_result): if logger.isEnabledFor(logging.DEBUG): @@ -1070,7 +1070,7 @@ def __init__(self, devID, warn=True): self.devID = devID def __str__(self): - return "Active: " + str(self.devID) + return f"Active: {str(self.devID)}" def evaluate(self, feature, notification, device, last_result): if logger.isEnabledFor(logging.DEBUG): @@ -1091,7 +1091,7 @@ def __init__(self, devID, warn=True): self.devID = devID def __str__(self): - return "Device: " + str(self.devID) + return f"Device: {str(self.devID)}" def evaluate(self, feature, notification, device, last_result): if logger.isEnabledFor(logging.DEBUG): @@ -1111,7 +1111,7 @@ def __init__(self, host, warn=True): self.host = host def __str__(self): - return "Host: " + str(self.host) + return f"Host: {str(self.host)}" def evaluate(self, feature, notification, device, last_result): if logger.isEnabledFor(logging.DEBUG): @@ -1389,7 +1389,7 @@ def __init__(self, args, warn=True): self.components = self.rule.components def __str__(self): - return "Later: [" + str(self.delay) + ", " + ", ".join(str(c) for c in self.components) + "]" + return f"Later: [{str(self.delay)}, " + ", ".join(str(c) for c in self.components) + "]" def evaluate(self, feature, notification, device, last_result): if self.delay and self.rule: @@ -1482,18 +1482,18 @@ def process_notification(device, notification, feature): new_g_keys_down = struct.unpack(" 0x00: # all other protocols are supposed to be almost the same diff --git a/lib/logitech_receiver/notify.py b/lib/logitech_receiver/notify.py index cd6e38b19..282bc51b5 100644 --- a/lib/logitech_receiver/notify.py +++ b/lib/logitech_receiver/notify.py @@ -91,7 +91,7 @@ def device_icon_list(name="_", kind=None): icon_list += ("input-mouse",) elif str(kind) == "headset": icon_list += ("audio-headphones", "audio-headset") - icon_list += ("input-" + str(kind),) + icon_list += (f"input-{str(kind)}",) _ICON_LISTS[name] = icon_list return icon_list diff --git a/lib/logitech_receiver/receiver.py b/lib/logitech_receiver/receiver.py index b63085d89..c9c312af1 100644 --- a/lib/logitech_receiver/receiver.py +++ b/lib/logitech_receiver/receiver.py @@ -467,7 +467,7 @@ def notification_information(self, number, notification): online = True encrypted = bool(notification.data[0] & 0x80) kind = hidpp10_constants.DEVICE_KIND[_get_kind_from_index(self, number)] - wpid = "00" + notification.data[2:3].hex().upper() + wpid = f"00{notification.data[2:3].hex().upper()}" return online, encrypted, wpid, kind def device_pairing_information(self, number: int) -> dict: diff --git a/lib/logitech_receiver/settings.py b/lib/logitech_receiver/settings.py index c9b816d87..a06f4f3b0 100644 --- a/lib/logitech_receiver/settings.py +++ b/lib/logitech_receiver/settings.py @@ -842,7 +842,7 @@ def __init__(self, options, byte_count=None): def to_string(self, value): def element_to_string(key, val): k = next((k for k in self.options if int(key) == k), None) - return str(k) + ":" + str(val) if k is not None else "?" + return f"{str(k)}:{str(val)}" if k is not None else "?" return "{" + ", ".join([element_to_string(k, value[k]) for k in value]) + "}" @@ -1107,7 +1107,7 @@ def __init__( def to_string(self, value): def element_to_string(key, val): k, c = next(((k, c) for k, c in self.choices.items() if int(key) == k), (None, None)) - return str(k) + ":" + str(c[val]) if k is not None else "?" + return f"{str(k)}:{str(c[val])}" if k is not None else "?" return "{" + ", ".join([element_to_string(k, value[k]) for k in sorted(value)]) + "}" diff --git a/lib/logitech_receiver/settings_templates.py b/lib/logitech_receiver/settings_templates.py index f259384c0..d080ec320 100644 --- a/lib/logitech_receiver/settings_templates.py +++ b/lib/logitech_receiver/settings_templates.py @@ -1140,11 +1140,11 @@ def _str_os_version(version): if version == 0: return "" elif version & 0xFF: - return str(version >> 8) + "." + str(version & 0xFF) + return f"{str(version >> 8)}.{str(version & 0xFF)}" else: return str(version >> 8) - return "" if low == 0 and high == 0 else " " + _str_os_version(low) + "-" + _str_os_version(high) + return "" if low == 0 and high == 0 else f" {_str_os_version(low)}-{_str_os_version(high)}" infos = device.feature_request(_F.MULTIPLATFORM) assert infos, "Oops, multiplatform count cannot be retrieved!" @@ -1200,7 +1200,7 @@ def build(cls, setting_class, device): choices = common.NamedInts() for host in range(0, numHosts): paired, hostName = hostNames.get(host, (True, "")) - choices[host] = str(host + 1) + ":" + hostName if hostName else str(host + 1) + choices[host] = f"{str(host + 1)}:{hostName}" if hostName else str(host + 1) return cls(choices=choices, read_skip_byte_count=1) if choices and len(choices) > 1 else None @@ -1709,7 +1709,7 @@ def build(cls, setting_class, device): key = ( setting_class.keys_universe[i] if i in setting_class.keys_universe - else common.NamedInt(i, "KEY " + str(i)) + else common.NamedInt(i, f"KEY {str(i)}") ) choices_map[key] = setting_class.choices_universe result = cls(choices_map) if choices_map else None diff --git a/lib/logitech_receiver/special_keys.py b/lib/logitech_receiver/special_keys.py index 0cce5ba2a..8e948b5cc 100644 --- a/lib/logitech_receiver/special_keys.py +++ b/lib/logitech_receiver/special_keys.py @@ -314,9 +314,9 @@ ) for i in range(1, 33): # add in G keys - these are not really Logitech Controls - CONTROL[0x1000 + i] = "G" + str(i) + CONTROL[0x1000 + i] = f"G{str(i)}" for i in range(1, 9): # add in M keys - these are not really Logitech Controls - CONTROL[0x1100 + i] = "M" + str(i) + CONTROL[0x1100 + i] = f"M{str(i)}" CONTROL[0x1200] = "MR" # add in MR key - this is not really a Logitech Control CONTROL._fallback = lambda x: f"unknown:{x:04X}" diff --git a/lib/solaar/cli/probe.py b/lib/solaar/cli/probe.py index d1a12ed59..576f7fa65 100644 --- a/lib/solaar/cli/probe.py +++ b/lib/solaar/cli/probe.py @@ -45,29 +45,29 @@ def run(receivers, args, find_receiver, _ignore): print("") print(" Register Dump") rgst = receiver.read_register(Registers.NOTIFICATIONS) - print(" Notifications %#04x: %s" % (Registers.NOTIFICATIONS % 0x100, "0x" + strhex(rgst) if rgst else "None")) + print(" Notifications %#04x: %s" % (Registers.NOTIFICATIONS % 0x100, f"0x{strhex(rgst)}" if rgst else "None")) rgst = receiver.read_register(Registers.RECEIVER_CONNECTION) print( " Connection State %#04x: %s" - % (Registers.RECEIVER_CONNECTION % 0x100, "0x" + strhex(rgst) if rgst else "None") + % (Registers.RECEIVER_CONNECTION % 0x100, f"0x{strhex(rgst)}" if rgst else "None") ) rgst = receiver.read_register(Registers.DEVICES_ACTIVITY) print( - " Device Activity %#04x: %s" % (Registers.DEVICES_ACTIVITY % 0x100, "0x" + strhex(rgst) if rgst else "None") + " Device Activity %#04x: %s" % (Registers.DEVICES_ACTIVITY % 0x100, f"0x{strhex(rgst)}" if rgst else "None") ) for sub_reg in range(0, 16): rgst = receiver.read_register(Registers.RECEIVER_INFO, sub_reg) print( " Pairing Register %#04x %#04x: %s" - % (Registers.RECEIVER_INFO % 0x100, sub_reg, "0x" + strhex(rgst) if rgst else "None") + % (Registers.RECEIVER_INFO % 0x100, sub_reg, f"0x{strhex(rgst)}" if rgst else "None") ) for device in range(0, 7): for sub_reg in [0x10, 0x20, 0x30, 0x50]: rgst = receiver.read_register(Registers.RECEIVER_INFO, sub_reg + device) print( " Pairing Register %#04x %#04x: %s" - % (Registers.RECEIVER_INFO % 0x100, sub_reg + device, "0x" + strhex(rgst) if rgst else "None") + % (Registers.RECEIVER_INFO % 0x100, sub_reg + device, f"0x{strhex(rgst)}" if rgst else "None") ) rgst = receiver.read_register(Registers.RECEIVER_INFO, 0x40 + device) print( @@ -90,7 +90,7 @@ def run(receivers, args, find_receiver, _ignore): rgst = receiver.read_register(Registers.FIRMWARE, sub_reg) print( " Firmware %#04x %#04x: %s" - % (Registers.FIRMWARE % 0x100, sub_reg, "0x" + strhex(rgst) if rgst is not None else "None") + % (Registers.FIRMWARE % 0x100, sub_reg, f"0x{strhex(rgst)}" if rgst is not None else "None") ) print("") @@ -106,7 +106,7 @@ def run(receivers, args, find_receiver, _ignore): if not isinstance(last, bytes) or not isinstance(rgst, bytes) or last != rgst: print( " Register Short %#04x %#04x: %s" - % (reg, sub, "0x" + strhex(rgst) if isinstance(rgst, bytes) else str(rgst)) + % (reg, sub, f"0x{strhex(rgst)}" if isinstance(rgst, bytes) else str(rgst)) ) last = rgst last = None @@ -120,6 +120,6 @@ def run(receivers, args, find_receiver, _ignore): if not isinstance(last, bytes) or not isinstance(rgst, bytes) or last != rgst: print( " Register Long %#04x %#04x: %s" - % (reg, sub, "0x" + strhex(rgst) if isinstance(rgst, bytes) else str(rgst)) + % (reg, sub, f"0x{strhex(rgst)}" if isinstance(rgst, bytes) else str(rgst)) ) last = rgst diff --git a/lib/solaar/cli/show.py b/lib/solaar/cli/show.py index f9650b2be..778c36f5b 100644 --- a/lib/solaar/cli/show.py +++ b/lib/solaar/cli/show.py @@ -80,8 +80,8 @@ def _battery_line(dev): level, nextLevel, status, voltage = battery.level, battery.next_level, battery.status, battery.voltage text = _battery_text(level) if voltage is not None: - text = text + f" {voltage}mV " - nextText = "" if nextLevel is None else ", next level " + _battery_text(nextLevel) + text = f"{text} {voltage}mV " + nextText = "" if nextLevel is None else f", next level {_battery_text(nextLevel)}" print(f" Battery: {text}, {status}{nextText}.") else: print(" Battery status unavailable.") diff --git a/lib/solaar/cli/unpair.py b/lib/solaar/cli/unpair.py index 03785be4e..c710b134c 100644 --- a/lib/solaar/cli/unpair.py +++ b/lib/solaar/cli/unpair.py @@ -26,8 +26,7 @@ def run(receivers, args, find_receiver, find_device): if not dev.receiver.may_unpair: print( - "Receiver with USB id %s for %s [%s:%s] does not unpair, but attempting anyway." - % (dev.receiver.product_id, dev.name, dev.wpid, dev.serial) + f"Receiver with USB id {dev.receiver.product_id} for {dev.name} [{dev.wpid}:{dev.serial}] does not unpair, but attempting anyway." ) try: # query these now, it's last chance to get them diff --git a/lib/solaar/gtk.py b/lib/solaar/gtk.py index 4641bcc69..55f2b6b79 100755 --- a/lib/solaar/gtk.py +++ b/lib/solaar/gtk.py @@ -162,9 +162,9 @@ def main(): udev_file = "42-logitech-unify-permissions.rules" if ( logger.isEnabledFor(logging.WARNING) - and not os.path.isfile("/etc/udev/rules.d/" + udev_file) - and not os.path.isfile("/usr/lib/udev/rules.d/" + udev_file) - and not os.path.isfile("/usr/local/lib/udev/rules.d/" + udev_file) + and not os.path.isfile(f"/etc/udev/rules.d/{udev_file}") + and not os.path.isfile(f"/usr/lib/udev/rules.d/{udev_file}") + and not os.path.isfile(f"/usr/local/lib/udev/rules.d/{udev_file}") ): logger.warning("Solaar udev file not found in expected location") logger.warning("See https://pwr-solaar.github.io/Solaar/installation for more information") diff --git a/lib/solaar/i18n.py b/lib/solaar/i18n.py index 1d4976ca3..be9865137 100644 --- a/lib/solaar/i18n.py +++ b/lib/solaar/i18n.py @@ -31,7 +31,7 @@ def _find_locale_path(locale_domain: str) -> str: src_share = os.path.normpath(os.path.join(os.path.realpath(sys.path[0]), "..", "share")) for location in prefix_share, src_share: - mo_files = glob(os.path.join(location, "locale", "*", "LC_MESSAGES", locale_domain + ".mo")) + mo_files = glob(os.path.join(location, "locale", "*", "LC_MESSAGES", f"{locale_domain}.mo")) if mo_files: return os.path.join(location, "locale") raise FileNotFoundError(f"Could not find locale path for {locale_domain}") diff --git a/lib/solaar/ui/config_panel.py b/lib/solaar/ui/config_panel.py index 2520ae893..884466003 100644 --- a/lib/solaar/ui/config_panel.py +++ b/lib/solaar/ui/config_panel.py @@ -375,7 +375,7 @@ def set_value(self, value): elem.set_state(v) if elem.get_state(): active += 1 - to_join.append(lbl.get_text() + ": " + str(elem.get_state())) + to_join.append(f"{lbl.get_text()}: {str(elem.get_state())}") b = ", ".join(to_join) self._button.set_label(f"{active} / {total}") self._button.set_tooltip_text(b) @@ -454,7 +454,7 @@ def set_value(self, value): item = ch._setting_item v = value.get(int(item), None) if v is not None: - b += str(item) + ": (" + b += f"{str(item)}: (" to_join = [] for c in ch._sub_items: sub_item = c._setting_sub_item @@ -464,7 +464,7 @@ def set_value(self, value): sub_item_value = c._control.get_value() c._control.set_value(sub_item_value) n += 1 - to_join.append(str(sub_item) + f"={sub_item_value}") + to_join.append(f"{str(sub_item)}={sub_item_value}") b += ", ".join(to_join) + ") " lbl_text = ngettext("%d value", "%d values", n) % n self._button.set_label(lbl_text) @@ -517,7 +517,7 @@ def set_value(self, value): h.control.set_value(v) else: v = self.sbox.setting._value[int(item)] - b += str(item) + ": (" + str(v) + ") " + b += f"{str(item)}: ({str(v)}) " lbl_text = ngettext("%d value", "%d values", n) % n self._button.set_label(lbl_text) self._button.set_tooltip_text(b) diff --git a/lib/solaar/ui/icons.py b/lib/solaar/ui/icons.py index 1900fd69f..f7ca42a95 100644 --- a/lib/solaar/ui/icons.py +++ b/lib/solaar/ui/icons.py @@ -105,7 +105,7 @@ def device_icon_set(name="_", kind=None): icon_set += ("input-mouse",) elif str(kind) == "headset": icon_set += ("audio-headphones", "audio-headset") - icon_set += ("input-" + str(kind),) + icon_set += (f"input-{str(kind)}", ) # icon_set += (name.replace(' ', '-'),) _ICON_SETS[name] = icon_set return icon_set diff --git a/lib/solaar/ui/rule_actions.py b/lib/solaar/ui/rule_actions.py index 56d80f2a1..6ad6fcd36 100644 --- a/lib/solaar/ui/rule_actions.py +++ b/lib/solaar/ui/rule_actions.py @@ -132,7 +132,7 @@ def left_label(cls, component): @classmethod def right_label(cls, component): - return " + ".join(component.key_names) + (" (" + component.action + ")" if component.action != CLICK else "") + return " + ".join(component.key_names) + (f" ({component.action})" if component.action != CLICK else "") class MouseScrollUI(ActionUI): diff --git a/lib/solaar/ui/rule_conditions.py b/lib/solaar/ui/rule_conditions.py index a5b65b94f..63b04217f 100644 --- a/lib/solaar/ui/rule_conditions.py +++ b/lib/solaar/ui/rule_conditions.py @@ -374,7 +374,7 @@ def left_label(cls, component): @classmethod def right_label(cls, component): - return component.test + (" " + repr(component.parameter) if component.parameter is not None else "") + return component.test + (f" {repr(component.parameter)}" if component.parameter is not None else "") @dataclass diff --git a/lib/solaar/ui/window.py b/lib/solaar/ui/window.py index f28ad7ce8..36c396995 100644 --- a/lib/solaar/ui/window.py +++ b/lib/solaar/ui/window.py @@ -503,7 +503,7 @@ def _details_items(device, read_all=False): yield (_("Path"), device.path) if device.kind is None: - yield (_("USB ID"), f"{LOGITECH_VENDOR_ID:04x}:" + device.product_id) + yield (_("USB ID"), f"{LOGITECH_VENDOR_ID:04x}:{device.product_id}") if read_all: yield (_("Serial"), device.serial) @@ -516,7 +516,7 @@ def _details_items(device, read_all=False): if device.wpid: yield (_("Wireless PID"), device.wpid) if device.product_id: - yield (_("Product ID"), f"{LOGITECH_VENDOR_ID:04x}:" + device.product_id) + yield (_("Product ID"), f"{LOGITECH_VENDOR_ID:04x}:{device.product_id}") hid_version = device.protocol yield (_("Protocol"), f"HID++ {hid_version:1.1f}" if hid_version else _("Unknown")) if read_all and device.polling_rate: @@ -532,7 +532,7 @@ def _details_items(device, read_all=False): if read_all: if device.firmware: for fw in list(device.firmware): - yield (" " + _(str(fw.kind)), (fw.name + " " + fw.version).strip()) + yield (f" {_(str(fw.kind))}", f"{fw.name} {fw.version}".strip()) elif device.kind is None or device.online: yield (f" {_('Firmware')}", "...") @@ -548,7 +548,7 @@ def _set_details(text): def _make_text(items): text = "\n".join("%-13s: %s" % (name, value) for name, value in items) - return "" + text + "" + return f"{text}" def _displayable_items(items): for name, value in items: @@ -850,7 +850,7 @@ def update(device, need_popup=False, refresh=False): else: path = device.receiver.path if device.receiver is not None else device.path - assert device.number is not None and device.number >= 0, "invalid device number" + str(device.number) + assert device.number is not None and device.number >= 0, f"invalid device number{str(device.number)}" item = _device_row(path, device.number, device if bool(device) else None) if bool(device) and item: diff --git a/tests/logitech_receiver/test_hidpp20_complex.py b/tests/logitech_receiver/test_hidpp20_complex.py index 632d30b7e..1674e9672 100644 --- a/tests/logitech_receiver/test_hidpp20_complex.py +++ b/tests/logitech_receiver/test_hidpp20_complex.py @@ -288,9 +288,9 @@ def test_ReprogrammableKeyV4_set(responses, index, diverted, persistently_divert ) def test_RemappableAction(r, index, cid, actionId, remapped, mask, status, action, modifiers, byts, remap, mocker): if int(remap, 16) == special_keys.KEYS_Default: - responses = r + [hidpp.Response("040000", 0x0000, "1C00"), hidpp.Response("00", 0x450, f"{cid:04X}" + "FF")] + responses = r + [hidpp.Response("040000", 0x0000, "1C00"), hidpp.Response("00", 0x450, f"{cid:04X}FF")] else: - responses = r + [hidpp.Response("040000", 0x0000, "1C00"), hidpp.Response("00", 0x440, f"{cid:04X}" + "FF" + remap)] + responses = r + [hidpp.Response("040000", 0x0000, "1C00"), hidpp.Response("00", 0x440, f"{cid:04X}FF{remap}")] device = hidpp.Device("KEY", responses=responses, feature=hidpp20_constants.FEATURE.REPROG_CONTROLS_V4, offset=5) key = hidpp20.PersistentRemappableAction(device, index, cid, actionId, remapped, mask, status) spy_request = mocker.spy(device, "request") From 6a1f7e1b2963a6b7be69cdc32bc092d9667010a6 Mon Sep 17 00:00:00 2001 From: DomHeadroom Date: Mon, 2 Sep 2024 08:34:31 +0200 Subject: [PATCH 2/3] Reverted print function change due to style violation --- lib/solaar/cli/unpair.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/solaar/cli/unpair.py b/lib/solaar/cli/unpair.py index c710b134c..03785be4e 100644 --- a/lib/solaar/cli/unpair.py +++ b/lib/solaar/cli/unpair.py @@ -26,7 +26,8 @@ def run(receivers, args, find_receiver, find_device): if not dev.receiver.may_unpair: print( - f"Receiver with USB id {dev.receiver.product_id} for {dev.name} [{dev.wpid}:{dev.serial}] does not unpair, but attempting anyway." + "Receiver with USB id %s for %s [%s:%s] does not unpair, but attempting anyway." + % (dev.receiver.product_id, dev.name, dev.wpid, dev.serial) ) try: # query these now, it's last chance to get them From 0cd602ba02ded959c84182e78515f4bd156d11ee Mon Sep 17 00:00:00 2001 From: DomHeadroom Date: Mon, 2 Sep 2024 09:45:33 +0200 Subject: [PATCH 3/3] Added ruff format changes --- lib/solaar/ui/icons.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/solaar/ui/icons.py b/lib/solaar/ui/icons.py index f7ca42a95..f65809034 100644 --- a/lib/solaar/ui/icons.py +++ b/lib/solaar/ui/icons.py @@ -105,7 +105,7 @@ def device_icon_set(name="_", kind=None): icon_set += ("input-mouse",) elif str(kind) == "headset": icon_set += ("audio-headphones", "audio-headset") - icon_set += (f"input-{str(kind)}", ) + icon_set += (f"input-{str(kind)}",) # icon_set += (name.replace(' ', '-'),) _ICON_SETS[name] = icon_set return icon_set