Skip to content

Commit

Permalink
device: don't ping device when getting name or codename
Browse files Browse the repository at this point in the history
  • Loading branch information
pfps committed May 23, 2024
1 parent c9dc232 commit c30a9ce
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
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

0 comments on commit c30a9ce

Please sign in to comment.