diff --git a/apps/bench.py b/apps/bench.py index 83625f0..4a60356 100644 --- a/apps/bench.py +++ b/apps/bench.py @@ -509,9 +509,11 @@ class Ping: packet = struct.pack( '>bbI', PacketType.SEQUENCE, - PACKET_FLAG_LAST - if self.current_packet_index == self.tx_packet_count - 1 - else 0, + ( + PACKET_FLAG_LAST + if self.current_packet_index == self.tx_packet_count - 1 + else 0 + ), self.current_packet_index, ) + bytes(self.tx_packet_size - 6) logging.info(color(f'Sending packet {self.current_packet_index}', 'yellow')) @@ -1062,9 +1064,9 @@ class Central(Connection.Listener): if self.phy not in (None, HCI_LE_1M_PHY): # Add an connections parameters entry for this PHY. - self.connection_parameter_preferences[ - self.phy - ] = connection_parameter_preferences + self.connection_parameter_preferences[self.phy] = ( + connection_parameter_preferences + ) else: self.connection_parameter_preferences = None diff --git a/apps/speaker/speaker.py b/apps/speaker/speaker.py index 84e05a0..fc2230a 100644 --- a/apps/speaker/speaker.py +++ b/apps/speaker/speaker.py @@ -76,6 +76,7 @@ logger = logging.getLogger(__name__) # ----------------------------------------------------------------------------- DEFAULT_UI_PORT = 7654 + # ----------------------------------------------------------------------------- class AudioExtractor: @staticmethod diff --git a/apps/unbond.py b/apps/unbond.py index 5ffd746..01cb9e5 100644 --- a/apps/unbond.py +++ b/apps/unbond.py @@ -24,6 +24,7 @@ from bumble.device import Device from bumble.keys import JsonKeyStore from bumble.transport import open_transport + # ----------------------------------------------------------------------------- async def unbond_with_keystore(keystore, address): if address is None: diff --git a/bumble/att.py b/bumble/att.py index 2bec4ea..0fce3ce 100644 --- a/bumble/att.py +++ b/bumble/att.py @@ -655,7 +655,7 @@ class ATT_Write_Command(ATT_PDU): @ATT_PDU.subclass( [ ('attribute_handle', HANDLE_FIELD_SPEC), - ('attribute_value', '*') + ('attribute_value', '*'), # ('authentication_signature', 'TODO') ] ) diff --git a/bumble/avdtp.py b/bumble/avdtp.py index f785109..567d258 100644 --- a/bumble/avdtp.py +++ b/bumble/avdtp.py @@ -1545,9 +1545,10 @@ class Protocol(EventEmitter): assert False # Should never reach this - async def get_capabilities( - self, seid: int - ) -> Union[Get_Capabilities_Response, Get_All_Capabilities_Response,]: + async def get_capabilities(self, seid: int) -> Union[ + Get_Capabilities_Response, + Get_All_Capabilities_Response, + ]: if self.version > (1, 2): return await self.send_command(Get_All_Capabilities_Command(seid)) diff --git a/bumble/avrcp.py b/bumble/avrcp.py index fec2b2c..11f4eff 100644 --- a/bumble/avrcp.py +++ b/bumble/avrcp.py @@ -1745,9 +1745,11 @@ class Protocol(pyee.EventEmitter): avc.CommandFrame.CommandType.CONTROL, avc.Frame.SubunitType.PANEL, 0, - avc.PassThroughFrame.StateFlag.PRESSED - if pressed - else avc.PassThroughFrame.StateFlag.RELEASED, + ( + avc.PassThroughFrame.StateFlag.PRESSED + if pressed + else avc.PassThroughFrame.StateFlag.RELEASED + ), key, b'', ) diff --git a/bumble/controller.py b/bumble/controller.py index eb20292..f4cbe95 100644 --- a/bumble/controller.py +++ b/bumble/controller.py @@ -134,15 +134,15 @@ class Controller: self.hci_sink = None self.link = link - self.central_connections: Dict[ - Address, Connection - ] = {} # Connections where this controller is the central - self.peripheral_connections: Dict[ - Address, Connection - ] = {} # Connections where this controller is the peripheral - self.classic_connections: Dict[ - Address, Connection - ] = {} # Connections in BR/EDR + self.central_connections: Dict[Address, Connection] = ( + {} + ) # Connections where this controller is the central + self.peripheral_connections: Dict[Address, Connection] = ( + {} + ) # Connections where this controller is the peripheral + self.classic_connections: Dict[Address, Connection] = ( + {} + ) # Connections in BR/EDR self.central_cis_links: Dict[int, CisLink] = {} # CIS links by handle self.peripheral_cis_links: Dict[int, CisLink] = {} # CIS links by handle diff --git a/bumble/device.py b/bumble/device.py index 48f9d58..10ce28a 100644 --- a/bumble/device.py +++ b/bumble/device.py @@ -276,12 +276,12 @@ class Advertisement: data_bytes: bytes = b'' # Constants - TX_POWER_NOT_AVAILABLE: ClassVar[ - int - ] = HCI_LE_Extended_Advertising_Report_Event.TX_POWER_INFORMATION_NOT_AVAILABLE - RSSI_NOT_AVAILABLE: ClassVar[ - int - ] = HCI_LE_Extended_Advertising_Report_Event.RSSI_NOT_AVAILABLE + TX_POWER_NOT_AVAILABLE: ClassVar[int] = ( + HCI_LE_Extended_Advertising_Report_Event.TX_POWER_INFORMATION_NOT_AVAILABLE + ) + RSSI_NOT_AVAILABLE: ClassVar[int] = ( + HCI_LE_Extended_Advertising_Report_Event.RSSI_NOT_AVAILABLE + ) def __post_init__(self) -> None: self.data = AdvertisingData.from_bytes(self.data_bytes) @@ -558,7 +558,9 @@ class AdvertisingParameters: ) primary_advertising_interval_min: int = DEVICE_DEFAULT_ADVERTISING_INTERVAL primary_advertising_interval_max: int = DEVICE_DEFAULT_ADVERTISING_INTERVAL - primary_advertising_channel_map: HCI_LE_Set_Extended_Advertising_Parameters_Command.ChannelMap = ( + primary_advertising_channel_map: ( + HCI_LE_Set_Extended_Advertising_Parameters_Command.ChannelMap + ) = ( AdvertisingChannelMap.CHANNEL_37 | AdvertisingChannelMap.CHANNEL_38 | AdvertisingChannelMap.CHANNEL_39 @@ -1138,14 +1140,12 @@ class Connection(CompositeEventEmitter): @overload async def create_l2cap_channel( self, spec: l2cap.ClassicChannelSpec - ) -> l2cap.ClassicChannel: - ... + ) -> l2cap.ClassicChannel: ... @overload async def create_l2cap_channel( self, spec: l2cap.LeCreditBasedChannelSpec - ) -> l2cap.LeCreditBasedChannel: - ... + ) -> l2cap.LeCreditBasedChannel: ... async def create_l2cap_channel( self, spec: Union[l2cap.ClassicChannelSpec, l2cap.LeCreditBasedChannelSpec] @@ -1723,16 +1723,14 @@ class Device(CompositeEventEmitter): self, connection: Connection, spec: l2cap.ClassicChannelSpec, - ) -> l2cap.ClassicChannel: - ... + ) -> l2cap.ClassicChannel: ... @overload async def create_l2cap_channel( self, connection: Connection, spec: l2cap.LeCreditBasedChannelSpec, - ) -> l2cap.LeCreditBasedChannel: - ... + ) -> l2cap.LeCreditBasedChannel: ... async def create_l2cap_channel( self, @@ -1753,16 +1751,14 @@ class Device(CompositeEventEmitter): self, spec: l2cap.ClassicChannelSpec, handler: Optional[Callable[[l2cap.ClassicChannel], Any]] = None, - ) -> l2cap.ClassicChannelServer: - ... + ) -> l2cap.ClassicChannelServer: ... @overload def create_l2cap_server( self, spec: l2cap.LeCreditBasedChannelSpec, handler: Optional[Callable[[l2cap.LeCreditBasedChannel], Any]] = None, - ) -> l2cap.LeCreditBasedChannelServer: - ... + ) -> l2cap.LeCreditBasedChannelServer: ... def create_l2cap_server( self, @@ -3289,17 +3285,19 @@ class Device(CompositeEventEmitter): handler = self.on( 'remote_name', - lambda address, remote_name: pending_name.set_result(remote_name) - if address == peer_address - else None, + lambda address, remote_name: ( + pending_name.set_result(remote_name) + if address == peer_address + else None + ), ) failure_handler = self.on( 'remote_name_failure', - lambda address, error_code: pending_name.set_exception( - HCI_Error(error_code) - ) - if address == peer_address - else None, + lambda address, error_code: ( + pending_name.set_exception(HCI_Error(error_code)) + if address == peer_address + else None + ), ) try: @@ -3475,9 +3473,9 @@ class Device(CompositeEventEmitter): LE features supported by the remote device. """ with closing(EventWatcher()) as watcher: - read_feature_future: asyncio.Future[ - LeFeatureMask - ] = asyncio.get_running_loop().create_future() + read_feature_future: asyncio.Future[LeFeatureMask] = ( + asyncio.get_running_loop().create_future() + ) def on_le_remote_features(handle: int, features: int): if handle == connection.handle: diff --git a/bumble/gap.py b/bumble/gap.py index 29df89f..c07a30d 100644 --- a/bumble/gap.py +++ b/bumble/gap.py @@ -36,6 +36,7 @@ logger = logging.getLogger(__name__) # Classes # ----------------------------------------------------------------------------- + # ----------------------------------------------------------------------------- class GenericAccessService(Service): def __init__(self, device_name, appearance=(0, 0)): diff --git a/bumble/gatt.py b/bumble/gatt.py index 71c01f4..896cec0 100644 --- a/bumble/gatt.py +++ b/bumble/gatt.py @@ -342,9 +342,11 @@ class Service(Attribute): uuid = UUID(uuid) super().__init__( - GATT_PRIMARY_SERVICE_ATTRIBUTE_TYPE - if primary - else GATT_SECONDARY_SERVICE_ATTRIBUTE_TYPE, + ( + GATT_PRIMARY_SERVICE_ATTRIBUTE_TYPE + if primary + else GATT_SECONDARY_SERVICE_ATTRIBUTE_TYPE + ), Attribute.READABLE, uuid.to_pdu_bytes(), ) @@ -560,9 +562,9 @@ class CharacteristicAdapter: def __init__(self, characteristic: Union[Characteristic, AttributeProxy]): self.wrapped_characteristic = characteristic - self.subscribers: Dict[ - Callable, Callable - ] = {} # Map from subscriber to proxy subscriber + self.subscribers: Dict[Callable, Callable] = ( + {} + ) # Map from subscriber to proxy subscriber if isinstance(characteristic, Characteristic): self.read_value = self.read_encoded_value diff --git a/bumble/gatt_client.py b/bumble/gatt_client.py index 2079a65..abb0de5 100644 --- a/bumble/gatt_client.py +++ b/bumble/gatt_client.py @@ -352,9 +352,7 @@ class Client: if c.uuid == uuid ] - def get_attribute_grouping( - self, attribute_handle: int - ) -> Optional[ + def get_attribute_grouping(self, attribute_handle: int) -> Optional[ Union[ ServiceProxy, Tuple[ServiceProxy, CharacteristicProxy], diff --git a/bumble/gatt_server.py b/bumble/gatt_server.py index 3be4185..be2b88e 100644 --- a/bumble/gatt_server.py +++ b/bumble/gatt_server.py @@ -445,9 +445,9 @@ class Server(EventEmitter): assert self.pending_confirmations[connection.handle] is None # Create a future value to hold the eventual response - pending_confirmation = self.pending_confirmations[ - connection.handle - ] = asyncio.get_running_loop().create_future() + pending_confirmation = self.pending_confirmations[connection.handle] = ( + asyncio.get_running_loop().create_future() + ) try: self.send_gatt_pdu(connection.handle, indication.to_bytes()) diff --git a/bumble/hci.py b/bumble/hci.py index 013a2d3..fba8951 100644 --- a/bumble/hci.py +++ b/bumble/hci.py @@ -4249,9 +4249,11 @@ class HCI_LE_Set_Extended_Scan_Parameters_Command(HCI_Command): fields.append( ( f'{scanning_phy_str}.scan_type: ', - 'PASSIVE' - if self.scan_types[i] == self.PASSIVE_SCANNING - else 'ACTIVE', + ( + 'PASSIVE' + if self.scan_types[i] == self.PASSIVE_SCANNING + else 'ACTIVE' + ), ) ) fields.append( @@ -5010,9 +5012,9 @@ class HCI_LE_Advertising_Report_Event(HCI_LE_Meta_Event): return f'{color(self.subevent_name(self.subevent_code), "magenta")}:\n{reports}' -HCI_LE_Meta_Event.subevent_classes[ - HCI_LE_ADVERTISING_REPORT_EVENT -] = HCI_LE_Advertising_Report_Event +HCI_LE_Meta_Event.subevent_classes[HCI_LE_ADVERTISING_REPORT_EVENT] = ( + HCI_LE_Advertising_Report_Event +) # ----------------------------------------------------------------------------- @@ -5264,9 +5266,9 @@ class HCI_LE_Extended_Advertising_Report_Event(HCI_LE_Meta_Event): return f'{color(self.subevent_name(self.subevent_code), "magenta")}:\n{reports}' -HCI_LE_Meta_Event.subevent_classes[ - HCI_LE_EXTENDED_ADVERTISING_REPORT_EVENT -] = HCI_LE_Extended_Advertising_Report_Event +HCI_LE_Meta_Event.subevent_classes[HCI_LE_EXTENDED_ADVERTISING_REPORT_EVENT] = ( + HCI_LE_Extended_Advertising_Report_Event +) # ----------------------------------------------------------------------------- diff --git a/bumble/hid.py b/bumble/hid.py index fc5c807..1b4aa00 100644 --- a/bumble/hid.py +++ b/bumble/hid.py @@ -48,6 +48,7 @@ HID_INTERRUPT_PSM = 0x0013 class Message: message_type: MessageType + # Report types class ReportType(enum.IntEnum): OTHER_REPORT = 0x00 diff --git a/bumble/keys.py b/bumble/keys.py index 198d5c4..5be5e09 100644 --- a/bumble/keys.py +++ b/bumble/keys.py @@ -128,10 +128,10 @@ class PairingKeys: def print(self, prefix=''): keys_dict = self.to_dict() - for (container_property, value) in keys_dict.items(): + for container_property, value in keys_dict.items(): if isinstance(value, dict): print(f'{prefix}{color(container_property, "cyan")}:') - for (key_property, key_value) in value.items(): + for key_property, key_value in value.items(): print(f'{prefix} {color(key_property, "green")}: {key_value}') else: print(f'{prefix}{color(container_property, "cyan")}: {value}') @@ -158,7 +158,7 @@ class KeyStore: async def get_resolving_keys(self): all_keys = await self.get_all() resolving_keys = [] - for (name, keys) in all_keys: + for name, keys in all_keys: if keys.irk is not None: if keys.address_type is None: address_type = Address.RANDOM_DEVICE_ADDRESS @@ -171,7 +171,7 @@ class KeyStore: async def print(self, prefix=''): entries = await self.get_all() separator = '' - for (name, keys) in entries: + for name, keys in entries: print(separator + prefix + color(name, 'yellow')) keys.print(prefix=prefix + ' ') separator = '\n' diff --git a/bumble/pandora/host.py b/bumble/pandora/host.py index e54d2d5..4904274 100644 --- a/bumble/pandora/host.py +++ b/bumble/pandora/host.py @@ -287,9 +287,9 @@ class HostService(HostServicer): self.log.debug(f"WaitDisconnection: {connection_handle}") if connection := self.device.lookup_connection(connection_handle): - disconnection_future: asyncio.Future[ - None - ] = asyncio.get_running_loop().create_future() + disconnection_future: asyncio.Future[None] = ( + asyncio.get_running_loop().create_future() + ) def on_disconnection(_: None) -> None: disconnection_future.set_result(None) @@ -370,9 +370,9 @@ class HostService(HostServicer): scan_response_data=scan_response_data, ) - pending_connection: asyncio.Future[ - bumble.device.Connection - ] = asyncio.get_running_loop().create_future() + pending_connection: asyncio.Future[bumble.device.Connection] = ( + asyncio.get_running_loop().create_future() + ) if request.connectable: @@ -516,9 +516,9 @@ class HostService(HostServicer): await asyncio.sleep(1) continue - pending_connection: asyncio.Future[ - bumble.device.Connection - ] = asyncio.get_running_loop().create_future() + pending_connection: asyncio.Future[bumble.device.Connection] = ( + asyncio.get_running_loop().create_future() + ) self.log.debug('Wait for LE connection...') connection = await pending_connection @@ -563,12 +563,14 @@ class HostService(HostServicer): legacy=request.legacy, active=not request.passive, own_address_type=request.own_address_type, - scan_interval=int(request.interval) - if request.interval - else DEVICE_DEFAULT_SCAN_INTERVAL, - scan_window=int(request.window) - if request.window - else DEVICE_DEFAULT_SCAN_WINDOW, + scan_interval=( + int(request.interval) + if request.interval + else DEVICE_DEFAULT_SCAN_INTERVAL + ), + scan_window=( + int(request.window) if request.window else DEVICE_DEFAULT_SCAN_WINDOW + ), scanning_phys=scanning_phys, ) @@ -782,9 +784,11 @@ class HostService(HostServicer): *struct.pack(' None: - ... + def on_packet(self, packet: bytes) -> None: ... class TransportSource(Protocol): terminated: asyncio.Future[None] - def set_packet_sink(self, sink: TransportSink) -> None: - ... + def set_packet_sink(self, sink: TransportSink) -> None: ... # ----------------------------------------------------------------------------- diff --git a/bumble/transport/usb.py b/bumble/transport/usb.py index 6479016..69e9649 100644 --- a/bumble/transport/usb.py +++ b/bumble/transport/usb.py @@ -449,7 +449,7 @@ async def open_usb_transport(spec: str) -> Transport: # Look for the first interface with the right class and endpoints def find_endpoints(device): # pylint: disable-next=too-many-nested-blocks - for (configuration_index, configuration) in enumerate(device): + for configuration_index, configuration in enumerate(device): interface = None for interface in configuration: setting = None diff --git a/bumble/utils.py b/bumble/utils.py index e6aae4d..4c9407f 100644 --- a/bumble/utils.py +++ b/bumble/utils.py @@ -117,12 +117,12 @@ class EventWatcher: self.handlers = [] @overload - def on(self, emitter: EventEmitter, event: str) -> Callable[[_Handler], _Handler]: - ... + def on( + self, emitter: EventEmitter, event: str + ) -> Callable[[_Handler], _Handler]: ... @overload - def on(self, emitter: EventEmitter, event: str, handler: _Handler) -> _Handler: - ... + def on(self, emitter: EventEmitter, event: str, handler: _Handler) -> _Handler: ... def on( self, emitter: EventEmitter, event: str, handler: Optional[_Handler] = None @@ -144,12 +144,14 @@ class EventWatcher: return wrapper if handler is None else wrapper(handler) @overload - def once(self, emitter: EventEmitter, event: str) -> Callable[[_Handler], _Handler]: - ... + def once( + self, emitter: EventEmitter, event: str + ) -> Callable[[_Handler], _Handler]: ... @overload - def once(self, emitter: EventEmitter, event: str, handler: _Handler) -> _Handler: - ... + def once( + self, emitter: EventEmitter, event: str, handler: _Handler + ) -> _Handler: ... def once( self, emitter: EventEmitter, event: str, handler: Optional[_Handler] = None diff --git a/examples/async_runner.py b/examples/async_runner.py index 9e71899..9bc004d 100644 --- a/examples/async_runner.py +++ b/examples/async_runner.py @@ -25,6 +25,7 @@ from bumble.utils import AsyncRunner my_work_queue1 = AsyncRunner.WorkQueue() my_work_queue2 = AsyncRunner.WorkQueue(create_task=False) + # ----------------------------------------------------------------------------- @AsyncRunner.run_in_task() async def func1(x, y): diff --git a/examples/run_device_with_snooper.py b/examples/run_device_with_snooper.py index 69a187f..be9a40e 100644 --- a/examples/run_device_with_snooper.py +++ b/examples/run_device_with_snooper.py @@ -25,6 +25,7 @@ from bumble.device import Device from bumble.transport import open_transport_or_link from bumble.snoop import BtSnooper + # ----------------------------------------------------------------------------- async def main(): if len(sys.argv) != 3: diff --git a/examples/run_hid_device.py b/examples/run_hid_device.py index 9aebfc2..26bc996 100644 --- a/examples/run_hid_device.py +++ b/examples/run_hid_device.py @@ -229,6 +229,7 @@ HID_REPORT_MAP = bytes( # Text String, 50 Octet Report Descriptor # Default protocol mode set to report protocol protocol_mode = Message.ProtocolMode.REPORT_PROTOCOL + # ----------------------------------------------------------------------------- def sdp_records(): service_record_handle = 0x00010002 @@ -427,6 +428,7 @@ class DeviceData: # Device's live data - Mouse and Keyboard will be stored in this deviceData = DeviceData() + # ----------------------------------------------------------------------------- async def keyboard_device(hid_device): diff --git a/setup.cfg b/setup.cfg index e29288b..062b796 100644 --- a/setup.cfg +++ b/setup.cfg @@ -87,7 +87,7 @@ test = pytest-html >= 3.2.0 coverage >= 6.4 development = - black == 22.10 + black == 24.3 grpcio-tools >= 1.57.0 invoke >= 1.7.3 mypy == 1.8.0 diff --git a/tests/core_test.py b/tests/core_test.py index 6c9d0c3..11afb1c 100644 --- a/tests/core_test.py +++ b/tests/core_test.py @@ -17,6 +17,7 @@ # ----------------------------------------------------------------------------- from bumble.core import AdvertisingData, UUID, get_dict_key_by_value + # ----------------------------------------------------------------------------- def test_ad_data(): data = bytes([2, AdvertisingData.TX_POWER_LEVEL, 123]) diff --git a/tests/self_test.py b/tests/self_test.py index 259de02..5c68ea0 100644 --- a/tests/self_test.py +++ b/tests/self_test.py @@ -316,13 +316,13 @@ async def _test_self_smp_with_configs(pairing_config1, pairing_config2): # Set up the pairing configs if pairing_config1: - two_devices.devices[ - 0 - ].pairing_config_factory = lambda connection: pairing_config1 + two_devices.devices[0].pairing_config_factory = ( + lambda connection: pairing_config1 + ) if pairing_config2: - two_devices.devices[ - 1 - ].pairing_config_factory = lambda connection: pairing_config2 + two_devices.devices[1].pairing_config_factory = ( + lambda connection: pairing_config2 + ) # Pair await two_devices.devices[0].pair(connection) diff --git a/tools/rtk_fw_download.py b/tools/rtk_fw_download.py index 89c49b2..74c783b 100644 --- a/tools/rtk_fw_download.py +++ b/tools/rtk_fw_download.py @@ -49,6 +49,7 @@ LINUX_FROM_SCRATCH_SOURCE = ( False, ) + # ----------------------------------------------------------------------------- # Functions # ----------------------------------------------------------------------------- @@ -111,7 +112,7 @@ def main(output_dir, source, single, force, parse): for driver_info in rtk.Driver.DRIVER_INFOS ] - for (fw_name, config_name, config_needed) in images: + for fw_name, config_name, config_needed in images: print(color("---", "yellow")) fw_image_out = output_dir / fw_name if not force and fw_image_out.exists():