diff --git a/bumble/avrcp.py b/bumble/avrcp.py index 5fe52d2..539253f 100644 --- a/bumble/avrcp.py +++ b/bumble/avrcp.py @@ -1147,7 +1147,9 @@ class Protocol(utils.EventEmitter): A 'connection' event will be emitted when a connection is made, and a 'start' event will be emitted when the protocol is ready to be used on that connection. """ - device.register_l2cap_server(avctp.AVCTP_PSM, self._on_avctp_connection) + device.create_l2cap_server( + l2cap.ClassicChannelSpec(avctp.AVCTP_PSM), self._on_avctp_connection + ) async def connect(self, connection: Connection) -> None: """ diff --git a/bumble/device.py b/bumble/device.py index ad33144..3be2189 100644 --- a/bumble/device.py +++ b/bumble/device.py @@ -1869,16 +1869,6 @@ class Connection(utils.CompositeEventEmitter): def send_l2cap_pdu(self, cid: int, pdu: bytes) -> None: self.device.send_l2cap_pdu(self.handle, cid, pdu) - @utils.deprecated("Please use create_l2cap_channel()") - async def open_l2cap_channel( - self, - psm, - max_credits=DEVICE_DEFAULT_L2CAP_COC_MAX_CREDITS, - mtu=DEVICE_DEFAULT_L2CAP_COC_MTU, - mps=DEVICE_DEFAULT_L2CAP_COC_MPS, - ): - return await self.device.open_l2cap_channel(self, psm, max_credits, mtu, mps) - @overload async def create_l2cap_channel( self, spec: l2cap.ClassicChannelSpec @@ -2591,36 +2581,6 @@ class Device(utils.CompositeEventEmitter): None, ) - @utils.deprecated("Please use create_l2cap_server()") - def register_l2cap_server(self, psm, server) -> int: - return self.l2cap_channel_manager.register_server(psm, server) - - @utils.deprecated("Please use create_l2cap_server()") - def register_l2cap_channel_server( - self, - psm, - server, - max_credits=DEVICE_DEFAULT_L2CAP_COC_MAX_CREDITS, - mtu=DEVICE_DEFAULT_L2CAP_COC_MTU, - mps=DEVICE_DEFAULT_L2CAP_COC_MPS, - ): - return self.l2cap_channel_manager.register_le_coc_server( - psm, server, max_credits, mtu, mps - ) - - @utils.deprecated("Please use create_l2cap_channel()") - async def open_l2cap_channel( - self, - connection, - psm, - max_credits=DEVICE_DEFAULT_L2CAP_COC_MAX_CREDITS, - mtu=DEVICE_DEFAULT_L2CAP_COC_MTU, - mps=DEVICE_DEFAULT_L2CAP_COC_MPS, - ): - return await self.l2cap_channel_manager.open_le_coc( - connection, psm, max_credits, mtu, mps - ) - @overload async def create_l2cap_channel( self, diff --git a/bumble/hid.py b/bumble/hid.py index 4a96e86..23006de 100644 --- a/bumble/hid.py +++ b/bumble/hid.py @@ -217,33 +217,41 @@ class HID(ABC, utils.EventEmitter): self.role = role # Register ourselves with the L2CAP channel manager - device.register_l2cap_server(HID_CONTROL_PSM, self.on_l2cap_connection) - device.register_l2cap_server(HID_INTERRUPT_PSM, self.on_l2cap_connection) + device.create_l2cap_server( + l2cap.ClassicChannelSpec(HID_CONTROL_PSM), self.on_l2cap_connection + ) + device.create_l2cap_server( + l2cap.ClassicChannelSpec(HID_INTERRUPT_PSM), self.on_l2cap_connection + ) device.on(device.EVENT_CONNECTION, self.on_device_connection) async def connect_control_channel(self) -> None: + if not self.connection: + raise InvalidStateError("Connection is not established!") # Create a new L2CAP connection - control channel try: - channel = await self.device.l2cap_channel_manager.connect( - self.connection, HID_CONTROL_PSM + channel = await self.connection.create_l2cap_channel( + l2cap.ClassicChannelSpec(HID_CONTROL_PSM) ) channel.sink = self.on_ctrl_pdu self.l2cap_ctrl_channel = channel except ProtocolError: - logging.exception(f'L2CAP connection failed.') + logging.exception('L2CAP connection failed.') raise async def connect_interrupt_channel(self) -> None: + if not self.connection: + raise InvalidStateError("Connection is not established!") # Create a new L2CAP connection - interrupt channel try: - channel = await self.device.l2cap_channel_manager.connect( - self.connection, HID_INTERRUPT_PSM + channel = await self.connection.create_l2cap_channel( + l2cap.ClassicChannelSpec(HID_CONTROL_PSM) ) channel.sink = self.on_intr_pdu self.l2cap_intr_channel = channel except ProtocolError: - logging.exception(f'L2CAP connection failed.') + logging.exception('L2CAP connection failed.') raise async def disconnect_interrupt_channel(self) -> None: diff --git a/bumble/l2cap.py b/bumble/l2cap.py index dfe0fe3..1a5b8d3 100644 --- a/bumble/l2cap.py +++ b/bumble/l2cap.py @@ -1531,16 +1531,6 @@ class ChannelManager: if cid in self.fixed_channels: del self.fixed_channels[cid] - @utils.deprecated("Please use create_classic_server") - def register_server( - self, - psm: int, - server: Callable[[ClassicChannel], Any], - ) -> int: - return self.create_classic_server( - handler=server, spec=ClassicChannelSpec(psm=psm) - ).psm - def create_classic_server( self, spec: ClassicChannelSpec, @@ -1577,22 +1567,6 @@ class ChannelManager: return self.servers[spec.psm] - @utils.deprecated("Please use create_le_credit_based_server()") - def register_le_coc_server( - self, - psm: int, - server: Callable[[LeCreditBasedChannel], Any], - max_credits: int, - mtu: int, - mps: int, - ) -> int: - return self.create_le_credit_based_server( - spec=LeCreditBasedChannelSpec( - psm=None if psm == 0 else psm, mtu=mtu, mps=mps, max_credits=max_credits - ), - handler=server, - ).psm - def create_le_credit_based_server( self, spec: LeCreditBasedChannelSpec, @@ -2145,17 +2119,6 @@ class ChannelManager: if channel.source_cid in connection_channels: del connection_channels[channel.source_cid] - @utils.deprecated("Please use create_le_credit_based_channel()") - async def open_le_coc( - self, connection: Connection, psm: int, max_credits: int, mtu: int, mps: int - ) -> LeCreditBasedChannel: - return await self.create_le_credit_based_channel( - connection=connection, - spec=LeCreditBasedChannelSpec( - psm=psm, max_credits=max_credits, mtu=mtu, mps=mps - ), - ) - async def create_le_credit_based_channel( self, connection: Connection, @@ -2202,12 +2165,6 @@ class ChannelManager: return channel - @utils.deprecated("Please use create_classic_channel()") - async def connect(self, connection: Connection, psm: int) -> ClassicChannel: - return await self.create_classic_channel( - connection=connection, spec=ClassicChannelSpec(psm=psm) - ) - async def create_classic_channel( self, connection: Connection, spec: ClassicChannelSpec ) -> ClassicChannel: @@ -2244,20 +2201,3 @@ class ChannelManager: raise e return channel - - -# ----------------------------------------------------------------------------- -# Deprecated Classes -# ----------------------------------------------------------------------------- - - -class Channel(ClassicChannel): - @utils.deprecated("Please use ClassicChannel") - def __init__(self, *args, **kwargs) -> None: - super().__init__(*args, **kwargs) - - -class LeConnectionOrientedChannel(LeCreditBasedChannel): - @utils.deprecated("Please use LeCreditBasedChannel") - def __init__(self, *args, **kwargs) -> None: - super().__init__(*args, **kwargs)