Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

device: don't ping device when getting name or codename #2494

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions lib/logitech_receiver/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@ def protocol(self):
@property
def codename(self):
if not self._codename:
if not self.online: # be very defensive
self.ping()
if self.online and self.protocol >= 2.0:
self._codename = _hidpp20.get_friendly_name(self)
if not self._codename:
Expand All @@ -189,20 +187,15 @@ def codename(self):
if codename:
self._codename = codename
elif self.protocol < 2.0:
self._codename = "? (%s)" % (self.wpid or hex(self.product_id)[2:].upper())
return self._codename or "?? (%s)" % (self.wpid or hex(self.product_id)[2:].upper())
self._codename = "? (%s)" % (self.wpid or self.product_id)
return self._codename or "?? (%s)" % (self.wpid or self.product_id)

@property
def name(self):
if not self._name:
if not self.online: # be very defensive
try:
self.ping()
except exceptions.NoSuchDevice:
pass
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 hex(self.product_id)[2:].upper()))
return self._name or self._codename or "Unknown device %s" % (self.wpid or self.product_id)

def get_ids(self):
ids = _hidpp20.get_ids(self)
Expand Down
16 changes: 8 additions & 8 deletions tests/logitech_receiver/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ class DeviceInfo:
serial: str = "aa:aa:aa;aa"


di_bad_handle = DeviceInfo(None, product_id=0xCCCC)
di_error = DeviceInfo(11, product_id=0xCCCC)
di_CCCC = DeviceInfo("11", product_id=0xCCCC)
di_C318 = DeviceInfo("11", product_id=0xC318)
di_B530 = DeviceInfo("11", product_id=0xB350, bus_id=0x0005)
di_C068 = DeviceInfo("11", product_id=0xC06B)
di_C08A = DeviceInfo("11", product_id=0xC08A)
di_DDDD = DeviceInfo("11", product_id=0xDDDD)
di_bad_handle = DeviceInfo(None, product_id="CCCC")
di_error = DeviceInfo(11, product_id="CCCC")
di_CCCC = DeviceInfo("11", product_id="CCCC")
di_C318 = DeviceInfo("11", product_id="C318")
di_B530 = DeviceInfo("11", product_id="B350", bus_id=0x0005)
di_C068 = DeviceInfo("11", product_id="C06B")
di_C08A = DeviceInfo("11", product_id="C08A")
di_DDDD = DeviceInfo("11", product_id="DDDD")


@pytest.mark.parametrize(
Expand Down
Loading