use ruff for linting and import sorting

This commit is contained in:
Gilles Boccon-Gibod
2025-12-29 19:28:45 -08:00
parent ad0753b959
commit 4fb501a0ef
59 changed files with 182 additions and 274 deletions

View File

@@ -59,28 +59,28 @@ class Keyboard:
def print_keyboard_report(self) -> None:
print(color('\tKeyboard Input Received', 'green', None, 'bold'))
print(color(f'Keys:', 'white', None, 'bold'))
print(color('Keys:', 'white', None, 'bold'))
for i in range(1, 7):
print(
color(f' Key{i}{" ":>8s}= ', 'cyan', None, 'bold'), self.report[i + 1]
)
print(color(f'\nModifier Keys:', 'white', None, 'bold'))
print(color('\nModifier Keys:', 'white', None, 'bold'))
print(
color(f' Left Ctrl : ', 'cyan'),
color(' Left Ctrl : ', 'cyan'),
f'{self.report[0][0] == 1!s:<5}', # type: ignore
color(f' Left Shift : ', 'cyan'),
color(' Left Shift : ', 'cyan'),
f'{self.report[0][1] == 1!s:<5}', # type: ignore
color(f' Left ALT : ', 'cyan'),
color(' Left ALT : ', 'cyan'),
f'{self.report[0][2] == 1!s:<5}', # type: ignore
color(f' Left GUI : ', 'cyan'),
color(' Left GUI : ', 'cyan'),
f'{self.report[0][3] == 1!s:<5}\n', # type: ignore
color(f' Right Ctrl : ', 'cyan'),
color(' Right Ctrl : ', 'cyan'),
f'{self.report[0][4] == 1!s:<5}', # type: ignore
color(f' Right Shift : ', 'cyan'),
color(' Right Shift : ', 'cyan'),
f'{self.report[0][5] == 1!s:<5}', # type: ignore
color(f' Right ALT : ', 'cyan'),
color(' Right ALT : ', 'cyan'),
f'{self.report[0][6] == 1!s:<5}', # type: ignore
color(f' Right GUI : ', 'cyan'),
color(' Right GUI : ', 'cyan'),
f'{self.report[0][7] == 1!s:<5}', # type: ignore
)
@@ -117,23 +117,23 @@ class Mouse:
def print_mouse_report(self) -> None:
print(color('\tMouse Input Received', 'green', None, 'bold'))
print(
color(f' Button 1 (primary/trigger) = ', 'cyan'),
color(' Button 1 (primary/trigger) = ', 'cyan'),
self.report[0][0] == 1, # type: ignore
color(f'\n Button 2 (secondary) = ', 'cyan'),
color('\n Button 2 (secondary) = ', 'cyan'),
self.report[0][1] == 1, # type: ignore
color(f'\n Button 3 (tertiary) = ', 'cyan'),
color('\n Button 3 (tertiary) = ', 'cyan'),
self.report[0][2] == 1, # type: ignore
color(f'\n Button4 = ', 'cyan'),
color('\n Button4 = ', 'cyan'),
self.report[0][3] == 1, # type: ignore
color(f'\n Button5 = ', 'cyan'),
color('\n Button5 = ', 'cyan'),
self.report[0][4] == 1, # type: ignore
color(f'\n X (X-axis displacement) = ', 'cyan'),
color('\n X (X-axis displacement) = ', 'cyan'),
self.report[1],
color(f'\n Y (Y-axis displacement) = ', 'cyan'),
color('\n Y (Y-axis displacement) = ', 'cyan'),
self.report[2],
color(f'\n Wheel = ', 'cyan'),
color('\n Wheel = ', 'cyan'),
self.report[3],
color(f'\n AC PAN = ', 'cyan'),
color('\n AC PAN = ', 'cyan'),
self.report[4],
)
@@ -142,7 +142,6 @@ class Mouse:
class ReportParser:
@staticmethod
def parse_input_report(input_report: bytes) -> None:
report_id = input_report[0] # pylint: disable=unsubscriptable-object
report_length = len(input_report)

View File

@@ -3,7 +3,6 @@ from mobly.controllers import android_device
class OneDeviceBenchTest(base_test.BaseTestClass):
def setup_class(self):
self.ads = self.register_controller(android_device)
self.dut = self.ads[0]

View File

@@ -33,9 +33,10 @@ from bumble.sdp import (
SDP_BLUETOOTH_PROFILE_DESCRIPTOR_LIST_ATTRIBUTE_ID,
SDP_PROTOCOL_DESCRIPTOR_LIST_ATTRIBUTE_ID,
SDP_SERVICE_CLASS_ID_LIST_ATTRIBUTE_ID,
DataElement,
ServiceAttribute,
)
from bumble.sdp import Client as SDP_Client
from bumble.sdp import DataElement, ServiceAttribute
from bumble.transport import open_transport

View File

@@ -30,6 +30,7 @@ from bumble.profiles.ancs import (
NotificationAttributeId,
)
from bumble.transport import open_transport
from bumble.utils import AsyncRunner
# -----------------------------------------------------------------------------
_cached_app_names: dict[str, str] = {}
@@ -192,9 +193,7 @@ async def main() -> None:
ancs_client.on("notification", on_ancs_notification)
# Process all notifications in a task.
notification_processing_task = asyncio.create_task(
process_notifications(ancs_client)
)
AsyncRunner.spawn(process_notifications(ancs_client))
# Accept a TCP connection to handle commands.
tcp_server = await asyncio.start_server(

View File

@@ -51,7 +51,6 @@ async def main() -> None:
devices[1].cis_enabled = True
await asyncio.gather(*[device.power_on() for device in devices])
advertising_set = await devices[0].create_advertising_set()
connection = await devices[1].connect(
devices[0].random_address, own_address_type=OwnAddressType.RANDOM

View File

@@ -38,11 +38,11 @@ class DiscoveryListener(Device.Listener):
print(f'>>> {color(address, "yellow")}:')
print(f' Device Class (raw): {class_of_device:06X}')
major_class_name = DeviceClass.major_device_class_name(major_device_class)
print(' Device Major Class: ' f'{major_class_name}')
print(f' Device Major Class: {major_class_name}')
minor_class_name = DeviceClass.minor_device_class_name(
major_device_class, minor_device_class
)
print(' Device Minor Class: ' f'{minor_class_name}')
print(f' Device Minor Class: {minor_class_name}')
print(
' Device Services: '
f'{", ".join(DeviceClass.service_class_labels(service_classes))}'

View File

@@ -32,7 +32,6 @@ from bumble.transport import open_transport
async def main(
config_file: str, transport: str, mode: int, peer_address: str, psm: int
) -> None:
print('<<< connecting to HCI...')
async with await open_transport(transport) as hci_transport:
print('<<< connected')
@@ -59,7 +58,6 @@ async def main(
active_channel: l2cap.ClassicChannel | None = None
def on_connection(channel: l2cap.ClassicChannel):
def on_sdu(sdu: bytes):
print(f'<<< {sdu.decode()}')

View File

@@ -1,86 +0,0 @@
# Copyright 2021-2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# -----------------------------------------------------------------------------
# Imports
# -----------------------------------------------------------------------------
import asyncio
import sys
import bumble.logging
from bumble.colors import color
from bumble.controller import Controller
from bumble.device import Device
from bumble.hci import Address
from bumble.link import LocalLink
from bumble.transport import open_transport
# -----------------------------------------------------------------------------
class ScannerListener(Device.Listener):
def on_advertisement(self, advertisement):
address_type_string = ('P', 'R', 'PI', 'RI')[advertisement.address.address_type]
address_color = 'yellow' if advertisement.is_connectable else 'red'
if address_type_string.startswith('P'):
type_color = 'green'
else:
type_color = 'cyan'
print(
f'>>> {color(advertisement.address, address_color)} '
f'[{color(address_type_string, type_color)}]: '
f'RSSI={advertisement.rssi}, {advertisement.data}'
)
# -----------------------------------------------------------------------------
async def main() -> None:
if len(sys.argv) != 2:
print('Usage: run_controller.py <transport-spec>')
print('example: run_controller_with_scanner.py serial:/dev/pts/14,1000000')
return
print('>>> connecting to HCI...')
async with await open_transport(sys.argv[1]) as hci_transport:
print('>>> connected')
# Create a local link
link = LocalLink()
# Create a first controller using the packet source/sink as its host interface
controller1 = Controller(
'C1',
host_source=hci_transport.source,
host_sink=hci_transport.sink,
link=link,
public_address='E0:E1:E2:E3:E4:E5',
)
# Create a second controller using the same link
controller2 = Controller('C2', link=link)
# Create a device with a scanner listener
device = Device.with_hci(
'Bumble', Address('F0:F1:F2:F3:F4:F5'), controller2, controller2
)
device.listener = ScannerListener()
await device.power_on()
await device.start_scanning()
await hci_transport.source.wait_for_termination()
# -----------------------------------------------------------------------------
bumble.logging.setup_basic_logging('DEBUG')
asyncio.run(main())

View File

@@ -36,7 +36,7 @@ async def main() -> None:
'Usage: run_csis_servers.py <config-file> '
'<transport-spec-for-device-1> <transport-spec-for-device-2>'
)
print('example: run_csis_servers.py device1.json ' 'hci-socket:0 hci-socket:1')
print('example: run_csis_servers.py device1.json hci-socket:0 hci-socket:1')
return
print('<<< connecting to HCI...')

View File

@@ -90,7 +90,7 @@ async def main() -> None:
),
scan_response_data=bytes(scan_response_data3),
)
print("Selected TX power 3:", set2.selected_tx_power)
print("Selected TX power 3:", set3.selected_tx_power)
await hci_transport.source.terminated

View File

@@ -30,9 +30,8 @@ from bumble.core import (
PhysicalTransport,
)
from bumble.device import Device
from bumble.hid import HID_CONTROL_PSM, HID_INTERRUPT_PSM
from bumble.hid import HID_CONTROL_PSM, HID_INTERRUPT_PSM, Message
from bumble.hid import Device as HID_Device
from bumble.hid import Message
from bumble.sdp import (
SDP_ADDITIONAL_PROTOCOL_DESCRIPTOR_LIST_ATTRIBUTE_ID,
SDP_BLUETOOTH_PROFILE_DESCRIPTOR_LIST_ATTRIBUTE_ID,
@@ -423,7 +422,6 @@ deviceData = DeviceData()
# -----------------------------------------------------------------------------
async def keyboard_device(hid_device: HID_Device):
# Start a Websocket server to receive events from a web page
async def serve(websocket: websockets.asyncio.server.ServerConnection):
global deviceData

View File

@@ -67,7 +67,6 @@ SDP_HID_SSR_HOST_MIN_TIMEOUT_ATTRIBUTE_ID = 0x0210
async def get_hid_device_sdp_record(connection):
# Connect to the SDP Server
sdp_client = SDP_Client(connection)
await sdp_client.connect()
@@ -84,7 +83,7 @@ async def get_hid_device_sdp_record(connection):
if len(service_record_handles) < 1:
await sdp_client.disconnect()
raise Exception(
color(f'BT HID Device service not found on peer device!!!!', 'red')
color('BT HID Device service not found on peer device!!!!', 'red')
)
# For BT_HUMAN_INTERFACE_DEVICE_SERVICE service, get all its attributes
@@ -92,8 +91,8 @@ async def get_hid_device_sdp_record(connection):
attributes = await sdp_client.get_attributes(
service_record_handle, [SDP_ALL_ATTRIBUTES_RANGE]
)
print(color(f'SERVICE {service_record_handle:04X} attributes:', 'yellow'))
print(color(f'SDP attributes for HID device', 'magenta'))
print(color('SERVICE {service_record_handle:04X} attributes:', 'yellow'))
print(color('SDP attributes for HID device', 'magenta'))
for attribute in attributes:
if attribute.id == SDP_SERVICE_RECORD_HANDLE_ATTRIBUTE_ID:
print(
@@ -287,7 +286,7 @@ async def main() -> None:
def on_hid_interrupt_data_cb(pdu: bytes):
report_type = pdu[0] & 0x0F
if len(pdu) == 1:
print(color(f'Warning: No report received', 'yellow'))
print(color('Warning: No report received', 'yellow'))
return
report_length = len(pdu[1:])
report_id = pdu[1]

View File

@@ -55,7 +55,7 @@ from bumble.transport import open_transport
# -----------------------------------------------------------------------------
async def main() -> None:
if len(sys.argv) < 3:
print('Usage: run_mcp_client.py <config-file>' '<transport-spec-for-device>')
print('Usage: run_mcp_client.py <config-file><transport-spec-for-device>')
return
print('<<< connecting to HCI...')

View File

@@ -28,9 +28,10 @@ from bumble.sdp import (
SDP_BLUETOOTH_PROFILE_DESCRIPTOR_LIST_ATTRIBUTE_ID,
SDP_PROTOCOL_DESCRIPTOR_LIST_ATTRIBUTE_ID,
SDP_SERVICE_CLASS_ID_LIST_ATTRIBUTE_ID,
DataElement,
ServiceAttribute,
)
from bumble.sdp import Client as SDP_Client
from bumble.sdp import DataElement, ServiceAttribute
from bumble.transport import open_transport

View File

@@ -57,7 +57,7 @@ def dumps_volume_state(volume_setting: int, muted: int, change_counter: int) ->
# -----------------------------------------------------------------------------
async def main() -> None:
if len(sys.argv) < 3:
print('Usage: run_vcp_renderer.py <config-file>' '<transport-spec-for-device>')
print('Usage: run_vcp_renderer.py <config-file><transport-spec-for-device>')
return
print('<<< connecting to HCI...')