diff --git a/lib/logitech_receiver/device.py b/lib/logitech_receiver/device.py index 10199fec..7bfb3b86 100644 --- a/lib/logitech_receiver/device.py +++ b/lib/logitech_receiver/device.py @@ -467,9 +467,7 @@ class Device: return False if enable: - set_flag_bits = ( - NotificationFlag.BATTERY_STATUS | NotificationFlag.UI | NotificationFlag.CONFIGURATION_COMPLETE - ).value + set_flag_bits = NotificationFlag.BATTERY_STATUS | NotificationFlag.UI | NotificationFlag.CONFIGURATION_COMPLETE else: set_flag_bits = 0 ok = _hidpp10.set_notification_flags(self, set_flag_bits) diff --git a/lib/logitech_receiver/hidpp10_constants.py b/lib/logitech_receiver/hidpp10_constants.py index b101e271..13a769d1 100644 --- a/lib/logitech_receiver/hidpp10_constants.py +++ b/lib/logitech_receiver/hidpp10_constants.py @@ -224,6 +224,25 @@ class DeviceFeature(Flag): https://drive.google.com/file/d/0BxbRzx7vEV7eNDBheWY0UHM5dEU/view?usp=sharing """ + @classmethod + def flag_names(cls, flag_bits: int) -> List[str]: + """Extract the names of the flags from the integer.""" + indexed = {item.value: item.name for item in cls} + + flag_names = [] + unknown_bits = flag_bits + for k in indexed: + # Ensure that the key (flag value) is a power of 2 (a single bit flag) + assert bin(k).count("1") == 1 + if k & flag_bits == k: + unknown_bits &= ~k + flag_names.append(indexed[k].replace("_", " ").lower()) + + # Yield any remaining unknown bits + if unknown_bits != 0: + flag_names.append(f"unknown:{unknown_bits:06X}") + return flag_names + RESERVED1 = 0x010000 SPECIAL_BUTTONS = 0x020000 ENHANCED_KEY_USAGE = 0x040000 diff --git a/lib/solaar/cli/pair.py b/lib/solaar/cli/pair.py index 02af3906..21343de6 100644 --- a/lib/solaar/cli/pair.py +++ b/lib/solaar/cli/pair.py @@ -39,8 +39,8 @@ def run(receivers, args, find_receiver, _ignore): # check if it's necessary to set the notification flags old_notification_flags = _hidpp10.get_notification_flags(receiver) or 0 - if not (old_notification_flags & hidpp10_constants.NOTIFICATION_FLAG.wireless): - _hidpp10.set_notification_flags(receiver, old_notification_flags | hidpp10_constants.NOTIFICATION_FLAG.wireless) + if not (old_notification_flags & hidpp10_constants.NotificationFlag.WIRELESS): + _hidpp10.set_notification_flags(receiver, old_notification_flags | hidpp10_constants.NotificationFlag.WIRELESS) # get all current devices known_devices = [dev.number for dev in receiver] @@ -121,7 +121,7 @@ def run(receivers, args, find_receiver, _ignore): if n: receiver.handle.notifications_hook(n) - if not (old_notification_flags & hidpp10_constants.NOTIFICATION_FLAG.wireless): + if not (old_notification_flags & hidpp10_constants.NotificationFlag.WIRELESS): # only clear the flags if they weren't set before, otherwise a # concurrently running Solaar app might stop working properly _hidpp10.set_notification_flags(receiver, old_notification_flags) diff --git a/lib/solaar/cli/show.py b/lib/solaar/cli/show.py index f13b9c5c..a0a9e5f6 100644 --- a/lib/solaar/cli/show.py +++ b/lib/solaar/cli/show.py @@ -131,14 +131,14 @@ def _print_device(dev, num=None): notification_flags = _hidpp10.get_notification_flags(dev) if notification_flags is not None: if notification_flags: - notification_names = hidpp10_constants.NOTIFICATION_FLAG.flag_names(notification_flags) + notification_names = hidpp10_constants.NotificationFlag.flag_names(notification_flags) print(f" Notifications: {', '.join(notification_names)} (0x{notification_flags:06X}).") else: print(" Notifications: (none).") device_features = _hidpp10.get_device_features(dev) if device_features is not None: if device_features: - device_features_names = hidpp10_constants.DEVICE_FEATURES.flag_names(device_features) + device_features_names = hidpp10_constants.DeviceFeature.flag_names(device_features) print(f" Features: {', '.join(device_features_names)} (0x{device_features:06X})") else: print(" Features: (none)")