Skip to content

Commit 72b6746

Browse files
committed
client list and selection won't crash when ble is not present
1 parent bb6ac60 commit 72b6746

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "meshcore-cli"
7-
version = "1.1.40"
7+
version = "1.1.41"
88
authors = [
99
{ name="Florent de Lamotte", email="[email protected]" },
1010
]

src/meshcore_cli/meshcore_cli.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import logging
1010
import requests
1111
from bleak import BleakScanner, BleakClient
12+
from bleak.exc import BleakError
1213
import serial.tools.list_ports
1314
from pathlib import Path
1415
import traceback
@@ -23,7 +24,7 @@
2324
from meshcore import MeshCore, EventType, logger
2425

2526
# Version
26-
VERSION = "v1.1.40"
27+
VERSION = "v1.1.41"
2728

2829
# default ble address is stored in a config file
2930
MCCLI_CONFIG_DIR = str(Path.home()) + "/.config/meshcore/"
@@ -2600,23 +2601,30 @@ async def main(argv):
26002601
return
26012602
case "-l" :
26022603
print("BLE devices:")
2603-
devices = await BleakScanner.discover(timeout=timeout)
2604-
if len(devices) == 0:
2605-
print(" No ble device found")
2606-
for d in devices :
2607-
if not d.name is None and d.name.startswith("MeshCore-"):
2608-
print(f" {d.address} {d.name}")
2604+
try :
2605+
devices = await BleakScanner.discover(timeout=timeout)
2606+
if len(devices) == 0:
2607+
print(" No ble device found")
2608+
for d in devices :
2609+
if not d.name is None and d.name.startswith("MeshCore-"):
2610+
print(f" {d.address} {d.name}")
2611+
except BleakError:
2612+
print(" No BLE HW")
26092613
print("\nSerial ports:")
26102614
ports = serial.tools.list_ports.comports()
26112615
for port, desc, hwid in sorted(ports):
26122616
print(f" {port:<18} {desc} [{hwid}]")
26132617
return
26142618
case "-S" :
2615-
devices = await BleakScanner.discover(timeout=timeout)
26162619
choices = []
2617-
for d in devices:
2618-
if not d.name is None and d.name.startswith("MeshCore-"):
2619-
choices.append(({"type":"ble","device":d}, f"{d.address:<22} {d.name}"))
2620+
2621+
try :
2622+
devices = await BleakScanner.discover(timeout=timeout)
2623+
for d in devices:
2624+
if not d.name is None and d.name.startswith("MeshCore-"):
2625+
choices.append(({"type":"ble","device":d}, f"{d.address:<22} {d.name}"))
2626+
except BleakError:
2627+
logger.info("No BLE Device")
26202628

26212629
ports = serial.tools.list_ports.comports()
26222630
for port, desc, hwid in sorted(ports):

0 commit comments

Comments
 (0)