Skip to content

Commit

Permalink
BleakClient: fix missing mtu_size property
Browse files Browse the repository at this point in the history
This was missed in #982 since BaseBleakClient didn't have an abstract
property for this.

This adds the base abstract property to the backends, fixes the missing
property in BleakClient client and adds it to the documentation.
  • Loading branch information
dlech committed Sep 23, 2022
1 parent be97338 commit 5c6b68a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
13 changes: 13 additions & 0 deletions bleak/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,19 @@ def address(self) -> str:
"""
return self._backend.address

@property
def mtu_size(self) -> int:
"""
Gets the negotiated MTU size in bytes for the active connection.
Consider using :attr:`bleak.backends.characteristic.BleakGATTCharacteristic.max_write_without_response_size` instead.
.. warning:: The BlueZ backend will always return 23 (the minimum MTU size).
See the ``mtu_size.py`` example for a way to hack around this.
"""
return self._backend.mtu_size

def __str__(self):
return f"{self.__class__.__name__}, {self.address}"

Expand Down
6 changes: 6 additions & 0 deletions bleak/backends/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ def __init__(self, address_or_ble_device: Union[BLEDevice, str], **kwargs):
self._timeout = kwargs.get("timeout", 10.0)
self._disconnected_callback = kwargs.get("disconnected_callback")

@property
@abc.abstractmethod
def mtu_size(self) -> int:
"""Gets the negotiated MTU."""
raise NotImplementedError

# Connectivity methods

def set_disconnected_callback(
Expand Down
2 changes: 2 additions & 0 deletions docs/api/client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ Device information

.. autoproperty:: bleak.BleakClient.address

.. autoproperty:: bleak.BleakClient.mtu_size


----------------------
GATT Client Operations
Expand Down

0 comments on commit 5c6b68a

Please sign in to comment.