mirror of
https://github.com/meshcore-dev/meshcore_py.git
synced 2026-04-20 22:13:49 +00:00
Merge pull request #53 from samm-git/patch-1
Add optional bleak package import handling
This commit is contained in:
commit
a124648885
1 changed files with 18 additions and 5 deletions
|
|
@ -5,11 +5,19 @@ mccli.py : CLI interface to MeschCore BLE companion app
|
|||
import asyncio
|
||||
import logging
|
||||
|
||||
from bleak import BleakClient, BleakScanner
|
||||
from bleak.backends.characteristic import BleakGATTCharacteristic
|
||||
from bleak.backends.device import BLEDevice
|
||||
from bleak.backends.scanner import AdvertisementData
|
||||
from bleak.exc import BleakDeviceNotFoundError
|
||||
|
||||
# Make bleak optional - only fail if BLE operations are attempted
|
||||
try:
|
||||
from bleak import BleakClient, BleakScanner
|
||||
from bleak.backends.characteristic import BleakGATTCharacteristic
|
||||
from bleak.backends.device import BLEDevice
|
||||
from bleak.backends.scanner import AdvertisementData
|
||||
from bleak.exc import BleakDeviceNotFoundError
|
||||
BLEAK_AVAILABLE = True
|
||||
except ImportError:
|
||||
BLEAK_AVAILABLE = False
|
||||
BleakClient = None
|
||||
BleakGATTCharacteristic = None
|
||||
|
||||
# Get logger
|
||||
logger = logging.getLogger("meshcore")
|
||||
|
|
@ -29,6 +37,11 @@ class BLEConnection:
|
|||
client (BleakClient, optional): An existing BleakClient instance.
|
||||
pin (str, optional): PIN for BLE pairing authentication.
|
||||
"""
|
||||
if not BLEAK_AVAILABLE:
|
||||
raise ImportError(
|
||||
f"BLE requires 'bleak' package to be installed."
|
||||
)
|
||||
|
||||
self.address = address
|
||||
self._user_provided_address = address
|
||||
self.client = client
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue