From 5b1d542d79c958649bdf32c21f175b8f72e3bf3a Mon Sep 17 00:00:00 2001 From: "Peter F. Patel-Schneider" Date: Sat, 15 Apr 2023 10:44:57 -0400 Subject: [PATCH] device: when finding name or codename ping if not known to be online --- lib/logitech_receiver/device.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/logitech_receiver/device.py b/lib/logitech_receiver/device.py index 104bdd34..d2cf5f14 100644 --- a/lib/logitech_receiver/device.py +++ b/lib/logitech_receiver/device.py @@ -170,35 +170,32 @@ class Device: @property def protocol(self): - if not self._protocol and self.online: - self._protocol = _base.ping( - self.handle or self.receiver.handle, self.number, long_message=self.bluetooth or self.hidpp_short is False - ) - # if the ping failed, the peripheral is (almost) certainly offline - self.online = self._protocol is not None - - # if _log.isEnabledFor(_DEBUG): - # _log.debug("device %d protocol %s", self.number, self._protocol) + if not self._protocol: + self.ping() return self._protocol or 0 @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: self._codename = self.name.split(' ', 1)[0] if self.name else None - elif self.receiver: + if not self._codename and self.receiver: codename = self.receiver.device_codename(self.number) if codename: self._codename = codename elif self.protocol < 2.0: self._codename = '? (%s)' % (self.wpid or self.product_id) - return self._codename if self._codename else '?? (%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 + self.ping() 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 self.product_id))