mirror of
https://github.com/smittix/intercept.git
synced 2026-07-07 00:58:12 -07:00
style: apply ruff-format to entire codebase
First-time run of ruff-format via pre-commit hook normalises quote style, trailing commas, and whitespace across 188 Python files. No logic changes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -61,7 +61,7 @@ class DBusScanner:
|
||||
self._lock = threading.Lock()
|
||||
self._known_devices: set[str] = set()
|
||||
|
||||
def start(self, transport: str = 'auto', rssi_threshold: int = -100) -> bool:
|
||||
def start(self, transport: str = "auto", rssi_threshold: int = -100) -> bool:
|
||||
"""
|
||||
Start DBus discovery.
|
||||
|
||||
@@ -100,26 +100,26 @@ class DBusScanner:
|
||||
# Set up signal handlers
|
||||
self._bus.add_signal_receiver(
|
||||
self._on_interfaces_added,
|
||||
signal_name='InterfacesAdded',
|
||||
signal_name="InterfacesAdded",
|
||||
dbus_interface=DBUS_OBJECT_MANAGER_INTERFACE,
|
||||
bus_name=BLUEZ_SERVICE,
|
||||
)
|
||||
|
||||
self._bus.add_signal_receiver(
|
||||
self._on_properties_changed,
|
||||
signal_name='PropertiesChanged',
|
||||
signal_name="PropertiesChanged",
|
||||
dbus_interface=DBUS_PROPERTIES_INTERFACE,
|
||||
path_keyword='path',
|
||||
path_keyword="path",
|
||||
)
|
||||
|
||||
# Set discovery filter
|
||||
try:
|
||||
filter_dict = {
|
||||
'Transport': dbus.String(transport if transport != 'auto' else 'auto'),
|
||||
'DuplicateData': dbus.Boolean(DISCOVERY_FILTER_DUPLICATE_DATA),
|
||||
"Transport": dbus.String(transport if transport != "auto" else "auto"),
|
||||
"DuplicateData": dbus.Boolean(DISCOVERY_FILTER_DUPLICATE_DATA),
|
||||
}
|
||||
if rssi_threshold > -100:
|
||||
filter_dict['RSSI'] = dbus.Int16(rssi_threshold)
|
||||
filter_dict["RSSI"] = dbus.Int16(rssi_threshold)
|
||||
|
||||
self._adapter.SetDiscoveryFilter(filter_dict)
|
||||
except dbus.exceptions.DBusException as e:
|
||||
@@ -129,7 +129,7 @@ class DBusScanner:
|
||||
try:
|
||||
self._adapter.StartDiscovery()
|
||||
except dbus.exceptions.DBusException as e:
|
||||
if 'InProgress' not in str(e):
|
||||
if "InProgress" not in str(e):
|
||||
logger.error(f"Failed to start discovery: {e}")
|
||||
return False
|
||||
|
||||
@@ -138,10 +138,7 @@ class DBusScanner:
|
||||
|
||||
# Start mainloop in background thread
|
||||
self._mainloop = GLib.MainLoop()
|
||||
self._mainloop_thread = threading.Thread(
|
||||
target=self._run_mainloop,
|
||||
daemon=True
|
||||
)
|
||||
self._mainloop_thread = threading.Thread(target=self._run_mainloop, daemon=True)
|
||||
self._mainloop_thread.start()
|
||||
|
||||
self._is_scanning = True
|
||||
@@ -201,10 +198,8 @@ class DBusScanner:
|
||||
"""Find the default Bluetooth adapter via DBus."""
|
||||
try:
|
||||
import dbus
|
||||
manager = dbus.Interface(
|
||||
self._bus.get_object(BLUEZ_SERVICE, '/'),
|
||||
DBUS_OBJECT_MANAGER_INTERFACE
|
||||
)
|
||||
|
||||
manager = dbus.Interface(self._bus.get_object(BLUEZ_SERVICE, "/"), DBUS_OBJECT_MANAGER_INTERFACE)
|
||||
|
||||
objects = manager.GetManagedObjects()
|
||||
for path, interfaces in objects.items():
|
||||
@@ -219,10 +214,8 @@ class DBusScanner:
|
||||
"""Process devices that already exist in BlueZ."""
|
||||
try:
|
||||
import dbus
|
||||
manager = dbus.Interface(
|
||||
self._bus.get_object(BLUEZ_SERVICE, '/'),
|
||||
DBUS_OBJECT_MANAGER_INTERFACE
|
||||
)
|
||||
|
||||
manager = dbus.Interface(self._bus.get_object(BLUEZ_SERVICE, "/"), DBUS_OBJECT_MANAGER_INTERFACE)
|
||||
|
||||
objects = manager.GetManagedObjects()
|
||||
for path, interfaces in objects.items():
|
||||
@@ -239,20 +232,15 @@ class DBusScanner:
|
||||
props = interfaces[BLUEZ_DEVICE_INTERFACE]
|
||||
self._process_device_properties(str(path), props)
|
||||
|
||||
def _on_properties_changed(
|
||||
self,
|
||||
interface: str,
|
||||
changed: dict,
|
||||
invalidated: list,
|
||||
path: str = None
|
||||
) -> None:
|
||||
def _on_properties_changed(self, interface: str, changed: dict, invalidated: list, path: str = None) -> None:
|
||||
"""Handle PropertiesChanged signal (device properties updated)."""
|
||||
if interface != BLUEZ_DEVICE_INTERFACE:
|
||||
return
|
||||
|
||||
if path and '/dev_' in path:
|
||||
if path and "/dev_" in path:
|
||||
try:
|
||||
import dbus
|
||||
|
||||
device_obj = self._bus.get_object(BLUEZ_SERVICE, path)
|
||||
props_iface = dbus.Interface(device_obj, DBUS_PROPERTIES_INTERFACE)
|
||||
all_props = props_iface.GetAll(BLUEZ_DEVICE_INTERFACE)
|
||||
@@ -265,40 +253,40 @@ class DBusScanner:
|
||||
try:
|
||||
import dbus
|
||||
|
||||
address = str(props.get('Address', ''))
|
||||
address = str(props.get("Address", ""))
|
||||
if not address:
|
||||
return
|
||||
|
||||
# Determine address type
|
||||
address_type = ADDRESS_TYPE_PUBLIC
|
||||
addr_type_raw = props.get('AddressType', 'public')
|
||||
addr_type_raw = props.get("AddressType", "public")
|
||||
if addr_type_raw:
|
||||
addr_type_str = str(addr_type_raw).lower()
|
||||
if 'random' in addr_type_str:
|
||||
if "random" in addr_type_str:
|
||||
address_type = ADDRESS_TYPE_RANDOM
|
||||
|
||||
# Extract name
|
||||
name = None
|
||||
if 'Name' in props:
|
||||
name = str(props['Name'])
|
||||
elif 'Alias' in props and props['Alias'] != address:
|
||||
name = str(props['Alias'])
|
||||
if "Name" in props:
|
||||
name = str(props["Name"])
|
||||
elif "Alias" in props and props["Alias"] != address:
|
||||
name = str(props["Alias"])
|
||||
|
||||
# Extract RSSI
|
||||
rssi = None
|
||||
if 'RSSI' in props:
|
||||
rssi = int(props['RSSI'])
|
||||
if "RSSI" in props:
|
||||
rssi = int(props["RSSI"])
|
||||
|
||||
# Extract TX Power
|
||||
tx_power = None
|
||||
if 'TxPower' in props:
|
||||
tx_power = int(props['TxPower'])
|
||||
if "TxPower" in props:
|
||||
tx_power = int(props["TxPower"])
|
||||
|
||||
# Extract manufacturer data
|
||||
manufacturer_id = None
|
||||
manufacturer_data = None
|
||||
if 'ManufacturerData' in props:
|
||||
mfr_data = props['ManufacturerData']
|
||||
if "ManufacturerData" in props:
|
||||
mfr_data = props["ManufacturerData"]
|
||||
if mfr_data:
|
||||
for mid, mdata in mfr_data.items():
|
||||
manufacturer_id = int(mid)
|
||||
@@ -314,14 +302,14 @@ class DBusScanner:
|
||||
|
||||
# Extract service UUIDs
|
||||
service_uuids = []
|
||||
if 'UUIDs' in props:
|
||||
for uuid in props['UUIDs']:
|
||||
if "UUIDs" in props:
|
||||
for uuid in props["UUIDs"]:
|
||||
service_uuids.append(str(uuid))
|
||||
|
||||
# Extract service data
|
||||
service_data = {}
|
||||
if 'ServiceData' in props:
|
||||
for uuid, data in props['ServiceData'].items():
|
||||
if "ServiceData" in props:
|
||||
for uuid, data in props["ServiceData"].items():
|
||||
try:
|
||||
if isinstance(data, (bytes, bytearray, dbus.Array, list, tuple)):
|
||||
service_data[str(uuid)] = bytes(data)
|
||||
@@ -334,18 +322,18 @@ class DBusScanner:
|
||||
class_of_device = None
|
||||
major_class = None
|
||||
minor_class = None
|
||||
if 'Class' in props:
|
||||
class_of_device = int(props['Class'])
|
||||
if "Class" in props:
|
||||
class_of_device = int(props["Class"])
|
||||
major_class, minor_class = self._decode_class_of_device(class_of_device)
|
||||
|
||||
# Connection state
|
||||
is_connected = bool(props.get('Connected', False))
|
||||
is_paired = bool(props.get('Paired', False))
|
||||
is_connected = bool(props.get("Connected", False))
|
||||
is_paired = bool(props.get("Paired", False))
|
||||
|
||||
# Appearance
|
||||
appearance = None
|
||||
if 'Appearance' in props:
|
||||
appearance = int(props['Appearance'])
|
||||
if "Appearance" in props:
|
||||
appearance = int(props["Appearance"])
|
||||
|
||||
# Create observation
|
||||
observation = BTObservation(
|
||||
|
||||
Reference in New Issue
Block a user