From a7d2e997763d262a826ec7abc76cce07b528ebe6 Mon Sep 17 00:00:00 2001 From: "Peter F. Patel-Schneider" Date: Sat, 18 Nov 2023 08:52:50 -0500 Subject: [PATCH] cli: handle NoSuchDevice exception when pinging device --- lib/solaar/cli/show.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/solaar/cli/show.py b/lib/solaar/cli/show.py index 284bb39be..b7fcd0093 100644 --- a/lib/solaar/cli/show.py +++ b/lib/solaar/cli/show.py @@ -16,6 +16,7 @@ ## with this program; if not, write to the Free Software Foundation, Inc., ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from logitech_receiver import base as _base from logitech_receiver import hidpp10 as _hidpp10 from logitech_receiver import hidpp20 as _hidpp20 from logitech_receiver import receiver as _receiver @@ -81,8 +82,12 @@ def _battery_line(dev): def _print_device(dev, num=None): assert dev is not None - # check if the device is online - dev.ping() + # try to ping the device to see if it actually exists and to wake it up + try: + dev.ping() + except _base.NoSuchDevice: + print(' %d: Device not found' % num or dev.number) + return print(' %d: %s' % (num or dev.number, dev.name)) print(' Device path :', dev.path)