From 72b67469b5974f4dde1554ac48df410e7a18be86 Mon Sep 17 00:00:00 2001 From: Florent de Lamotte Date: Thu, 30 Oct 2025 16:32:33 +0100 Subject: [PATCH] client list and selection won't crash when ble is not present --- pyproject.toml | 2 +- src/meshcore_cli/meshcore_cli.py | 30 +++++++++++++++++++----------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5df25a9..7e1ab5c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "meshcore-cli" -version = "1.1.40" +version = "1.1.41" authors = [ { name="Florent de Lamotte", email="florent@frizoncorrea.fr" }, ] diff --git a/src/meshcore_cli/meshcore_cli.py b/src/meshcore_cli/meshcore_cli.py index d6e55b1..4343cf1 100644 --- a/src/meshcore_cli/meshcore_cli.py +++ b/src/meshcore_cli/meshcore_cli.py @@ -9,6 +9,7 @@ import getopt, json, shlex, re import logging import requests from bleak import BleakScanner, BleakClient +from bleak.exc import BleakError import serial.tools.list_ports from pathlib import Path import traceback @@ -23,7 +24,7 @@ from prompt_toolkit.shortcuts import radiolist_dialog from meshcore import MeshCore, EventType, logger # Version -VERSION = "v1.1.40" +VERSION = "v1.1.41" # default ble address is stored in a config file MCCLI_CONFIG_DIR = str(Path.home()) + "/.config/meshcore/" @@ -2600,23 +2601,30 @@ async def main(argv): return case "-l" : print("BLE devices:") - devices = await BleakScanner.discover(timeout=timeout) - if len(devices) == 0: - print(" No ble device found") - for d in devices : - if not d.name is None and d.name.startswith("MeshCore-"): - print(f" {d.address} {d.name}") + try : + devices = await BleakScanner.discover(timeout=timeout) + if len(devices) == 0: + print(" No ble device found") + for d in devices : + if not d.name is None and d.name.startswith("MeshCore-"): + print(f" {d.address} {d.name}") + except BleakError: + print(" No BLE HW") print("\nSerial ports:") ports = serial.tools.list_ports.comports() for port, desc, hwid in sorted(ports): print(f" {port:<18} {desc} [{hwid}]") return case "-S" : - devices = await BleakScanner.discover(timeout=timeout) choices = [] - for d in devices: - if not d.name is None and d.name.startswith("MeshCore-"): - choices.append(({"type":"ble","device":d}, f"{d.address:<22} {d.name}")) + + try : + devices = await BleakScanner.discover(timeout=timeout) + for d in devices: + if not d.name is None and d.name.startswith("MeshCore-"): + choices.append(({"type":"ble","device":d}, f"{d.address:<22} {d.name}")) + except BleakError: + logger.info("No BLE Device") ports = serial.tools.list_ports.comports() for port, desc, hwid in sorted(ports):