From a966bbff6f3094ffa867b789c8df96ce9f530ff4 Mon Sep 17 00:00:00 2001 From: Daniel Pavel Date: Fri, 12 Jul 2013 22:23:03 +0200 Subject: [PATCH] fixed handling of protocol version when the device is offline --- lib/logitech/unifying_receiver/hidpp10.py | 8 +++----- lib/logitech/unifying_receiver/hidpp20.py | 2 +- lib/logitech/unifying_receiver/receiver.py | 4 ++-- lib/logitech/unifying_receiver/settings_templates.py | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/logitech/unifying_receiver/hidpp10.py b/lib/logitech/unifying_receiver/hidpp10.py index b6ea7531..9069fb80 100644 --- a/lib/logitech/unifying_receiver/hidpp10.py +++ b/lib/logitech/unifying_receiver/hidpp10.py @@ -140,7 +140,7 @@ def get_battery(device): return """Reads a device's battery level, if provided by the HID++ 1.0 protocol.""" - if device.protocol >= 2.0: + if device.protocol and device.protocol >= 2.0: # let's just assume HID++ 2.0 devices do not provide the battery info in a register return @@ -288,8 +288,7 @@ def get_notification_flags(device): # or the device does not support registers. if device.kind is not None: # peripherals with protocol >= 2.0 don't support registers - p = device.protocol - if p is not None and p >= 2.0: + if device.protocol and device.protocol >= 2.0: return flags = read_register(device, REGISTERS.notifications) @@ -305,8 +304,7 @@ def set_notification_flags(device, *flag_bits): # or the device does not support registers. if device.kind is not None: # peripherals with protocol >= 2.0 don't support registers - p = device.protocol - if p is not None and p >= 2.0: + if device.protocol and device.protocol >= 2.0: return flag_bits = sum(int(b) for b in flag_bits) diff --git a/lib/logitech/unifying_receiver/hidpp20.py b/lib/logitech/unifying_receiver/hidpp20.py index f75e246d..5e3c7c4e 100644 --- a/lib/logitech/unifying_receiver/hidpp20.py +++ b/lib/logitech/unifying_receiver/hidpp20.py @@ -146,7 +146,7 @@ class FeaturesArray(object): return False # I _think_ this is universally true - if self.device.protocol is not None and self.device.protocol < 2.0: + if self.device.protocol and self.device.protocol < 2.0: self.supported = False self.device.features = None self.device = None diff --git a/lib/logitech/unifying_receiver/receiver.py b/lib/logitech/unifying_receiver/receiver.py index d0561be4..6507f183 100644 --- a/lib/logitech/unifying_receiver/receiver.py +++ b/lib/logitech/unifying_receiver/receiver.py @@ -143,7 +143,7 @@ class PairedDevice(object): @property def name(self): if self._name is None: - if self.protocol >= 2.0 and self.online: + 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) @@ -155,7 +155,7 @@ class PairedDevice(object): kind = ord(pair_info[7:8]) & 0x0F self._kind = _hidpp10.DEVICE_KIND[kind] self._polling_rate = ord(pair_info[2:3]) - elif self.protocol >= 2.0: + elif self.online and self.protocol >= 2.0: self._kind = _hidpp20.get_kind(self) return self._kind or '?' diff --git a/lib/logitech/unifying_receiver/settings_templates.py b/lib/logitech/unifying_receiver/settings_templates.py index 083ecc04..95a3f94e 100644 --- a/lib/logitech/unifying_receiver/settings_templates.py +++ b/lib/logitech/unifying_receiver/settings_templates.py @@ -130,7 +130,7 @@ def check_feature_settings(device, already_known): """Try to auto-detect device settings by the HID++ 2.0 features they have.""" if device.features is None: return - if device.protocol is not None and device.protocol < 2.0: + if device.protocol and device.protocol < 2.0: return if not any(s.name == _FN_SWAP[0] for s in already_known) and _F.FN_INVERSION in device.features: fn_swap = FeatureSettings.fn_swap()