Skip to content

Commit 021db78

Browse files
committed
aioble/l2cap: Use DeviceDisconnectedError directly.
L2CAPChannel.__init__ raised ValueError("Not connected") when the connection was already disconnected. Change this to raise DeviceDisconnectedError directly, which is the exception callers (e.g. l2cap_file_server example) already catch. Also make L2CAPDisconnectedError a subclass of DeviceDisconnectedError so that mid-operation L2CAP disconnections are caught by the same handler. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
1 parent d0511a4 commit 021db78

File tree

1 file changed

+3
-3
lines changed
  • micropython/bluetooth/aioble/aioble

1 file changed

+3
-3
lines changed

micropython/bluetooth/aioble/aioble/l2cap.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import asyncio
77

88
from .core import ble, log_error, register_irq_handler
9-
from .device import DeviceConnection
9+
from .device import DeviceConnection, DeviceDisconnectedError
1010

1111

1212
_IRQ_L2CAP_ACCEPT = const(22)
@@ -63,7 +63,7 @@ def _l2cap_shutdown():
6363

6464

6565
# The channel was disconnected during a send/recvinto/flush.
66-
class L2CAPDisconnectedError(Exception):
66+
class L2CAPDisconnectedError(DeviceDisconnectedError):
6767
pass
6868

6969

@@ -75,7 +75,7 @@ class L2CAPConnectionError(Exception):
7575
class L2CAPChannel:
7676
def __init__(self, connection):
7777
if not connection.is_connected():
78-
raise ValueError("Not connected")
78+
raise DeviceDisconnectedError
7979

8080
if connection._l2cap_channel:
8181
raise ValueError("Already has channel")

0 commit comments

Comments
 (0)