diff --git a/bleak/__init__.py b/bleak/__init__.py index 95a2d3b1..facd153c 100644 --- a/bleak/__init__.py +++ b/bleak/__init__.py @@ -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}" diff --git a/bleak/backends/client.py b/bleak/backends/client.py index 654ebb7f..6bcdf760 100644 --- a/bleak/backends/client.py +++ b/bleak/backends/client.py @@ -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( diff --git a/docs/api/client.rst b/docs/api/client.rst index 59a237e8..b255f1e7 100644 --- a/docs/api/client.rst +++ b/docs/api/client.rst @@ -49,6 +49,8 @@ Device information .. autoproperty:: bleak.BleakClient.address +.. autoproperty:: bleak.BleakClient.mtu_size + ---------------------- GATT Client Operations