From 29525ddfbfd5489f6c94e6f4d196c50f162202c9 Mon Sep 17 00:00:00 2001 From: Josh Wu Date: Thu, 6 Nov 2025 19:04:42 +0800 Subject: [PATCH] Add is_disconnected property --- bumble/device.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/bumble/device.py b/bumble/device.py index f80be302..d254cd01 100644 --- a/bumble/device.py +++ b/bumble/device.py @@ -1447,6 +1447,10 @@ async def disconnect( ) -> None: await self.device.disconnect(self, reason) + @property + def is_connected(self) -> bool: + return self in self.device.sco_links.values() + # ----------------------------------------------------------------------------- class _IsoLink: @@ -1644,6 +1648,10 @@ async def disconnect( ) -> None: await self.device.disconnect(self, reason) + @property + def is_connected(self) -> bool: + return self in self.device.cis_links.values() + # ----------------------------------------------------------------------------- @dataclass @@ -1870,7 +1878,11 @@ def is_encrypted(self) -> bool: @property def is_incomplete(self) -> bool: - return self.handle is None + return self.handle == 0 + + @property + def is_connected(self) -> bool: + return self in self.device.connections.values() def send_l2cap_pdu(self, cid: int, pdu: bytes) -> None: self.device.send_l2cap_pdu(self.handle, cid, pdu) @@ -1913,6 +1925,8 @@ async def switch_role(self, role: hci.Role) -> None: async def sustain(self, timeout: Optional[float] = None) -> None: """Idles the current task waiting for a disconnect or timeout""" + if not self.is_connected: + return abort = asyncio.get_running_loop().create_future() self.on(self.EVENT_DISCONNECTION, abort.set_result)