diff --git a/micropython/bluetooth/aioble/aioble/device.py b/micropython/bluetooth/aioble/aioble/device.py index 93819bc1e..feece62ea 100644 --- a/micropython/bluetooth/aioble/aioble/device.py +++ b/micropython/bluetooth/aioble/aioble/device.py @@ -273,7 +273,7 @@ def timeout(self, timeout_ms): async def exchange_mtu(self, mtu=None, timeout_ms=1000): if not self.is_connected(): - raise ValueError("Not connected") + raise DeviceDisconnectedError if mtu: ble.config(mtu=mtu) diff --git a/micropython/bluetooth/aioble/aioble/l2cap.py b/micropython/bluetooth/aioble/aioble/l2cap.py index 397b7ceb6..8330f6535 100644 --- a/micropython/bluetooth/aioble/aioble/l2cap.py +++ b/micropython/bluetooth/aioble/aioble/l2cap.py @@ -6,7 +6,7 @@ import asyncio from .core import ble, log_error, register_irq_handler -from .device import DeviceConnection +from .device import DeviceConnection, DeviceDisconnectedError _IRQ_L2CAP_ACCEPT = const(22) @@ -63,7 +63,7 @@ def _l2cap_shutdown(): # The channel was disconnected during a send/recvinto/flush. -class L2CAPDisconnectedError(Exception): +class L2CAPDisconnectedError(DeviceDisconnectedError): pass @@ -75,7 +75,7 @@ class L2CAPConnectionError(Exception): class L2CAPChannel: def __init__(self, connection): if not connection.is_connected(): - raise ValueError("Not connected") + raise L2CAPDisconnectedError if connection._l2cap_channel: raise ValueError("Already has channel") diff --git a/micropython/bluetooth/aioble/aioble/server.py b/micropython/bluetooth/aioble/aioble/server.py index 5d5d7399b..392381923 100644 --- a/micropython/bluetooth/aioble/aioble/server.py +++ b/micropython/bluetooth/aioble/aioble/server.py @@ -15,7 +15,7 @@ register_irq_handler, GattError, ) -from .device import DeviceConnection, DeviceTimeout +from .device import DeviceConnection, DeviceDisconnectedError, DeviceTimeout _registered_characteristics = {} @@ -263,7 +263,7 @@ async def indicate(self, connection, data=None, timeout_ms=1000): if self._indicate_connection is not None: raise ValueError("In progress") if not connection.is_connected(): - raise ValueError("Not connected") + raise DeviceDisconnectedError self._indicate_connection = connection self._indicate_status = None