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

This commit is contained in:
Peter F. Patel-Schneider 2024-05-22 21:09:08 -04:00
parent c9dc232951
commit 90b0db6c3b
2 changed files with 11 additions and 18 deletions

View File

@ -178,8 +178,6 @@ class Device:
@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:
@ -189,20 +187,15 @@ class Device:
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)

View File

@ -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(