forked from auracaster/bumble_mirror
Ruff: Add and fix UP rules
This commit is contained in:
@@ -23,7 +23,8 @@ import contextlib
|
||||
import dataclasses
|
||||
import functools
|
||||
import logging
|
||||
from typing import Any, AsyncGenerator, Coroutine, Optional
|
||||
from collections.abc import AsyncGenerator, Coroutine
|
||||
from typing import Any
|
||||
|
||||
import click
|
||||
|
||||
@@ -112,12 +113,12 @@ class BroadcastScanner(bumble.utils.EventEmitter):
|
||||
sync: bumble.device.PeriodicAdvertisingSync
|
||||
broadcast_id: int
|
||||
rssi: int = 0
|
||||
public_broadcast_announcement: Optional[pbp.PublicBroadcastAnnouncement] = None
|
||||
broadcast_audio_announcement: Optional[bap.BroadcastAudioAnnouncement] = None
|
||||
basic_audio_announcement: Optional[bap.BasicAudioAnnouncement] = None
|
||||
appearance: Optional[core.Appearance] = None
|
||||
biginfo: Optional[bumble.device.BigInfoAdvertisement] = None
|
||||
manufacturer_data: Optional[tuple[str, bytes]] = None
|
||||
public_broadcast_announcement: pbp.PublicBroadcastAnnouncement | None = None
|
||||
broadcast_audio_announcement: bap.BroadcastAudioAnnouncement | None = None
|
||||
basic_audio_announcement: bap.BasicAudioAnnouncement | None = None
|
||||
appearance: core.Appearance | None = None
|
||||
biginfo: bumble.device.BigInfoAdvertisement | None = None
|
||||
manufacturer_data: tuple[str, bytes] | None = None
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
super().__init__()
|
||||
@@ -433,7 +434,7 @@ async def create_device(transport: str) -> AsyncGenerator[bumble.device.Device,
|
||||
|
||||
|
||||
async def find_broadcast_by_name(
|
||||
device: bumble.device.Device, name: Optional[str]
|
||||
device: bumble.device.Device, name: str | None
|
||||
) -> BroadcastScanner.Broadcast:
|
||||
result = asyncio.get_running_loop().create_future()
|
||||
|
||||
@@ -474,8 +475,8 @@ async def run_scan(
|
||||
|
||||
|
||||
async def run_assist(
|
||||
broadcast_name: Optional[str],
|
||||
source_id: Optional[int],
|
||||
broadcast_name: str | None,
|
||||
source_id: int | None,
|
||||
command: str,
|
||||
transport: str,
|
||||
address: str,
|
||||
@@ -658,7 +659,7 @@ async def run_pair(transport: str, address: str) -> None:
|
||||
|
||||
async def run_receive(
|
||||
transport: str,
|
||||
broadcast_id: Optional[int],
|
||||
broadcast_id: int | None,
|
||||
output: str,
|
||||
broadcast_code: str | None,
|
||||
sync_timeout: float,
|
||||
|
||||
@@ -22,7 +22,6 @@ import logging
|
||||
import statistics
|
||||
import struct
|
||||
import time
|
||||
from typing import Optional
|
||||
|
||||
import click
|
||||
|
||||
@@ -257,8 +256,8 @@ async def pre_power_on(device: Device, classic: bool) -> None:
|
||||
|
||||
async def post_power_on(
|
||||
device: Device,
|
||||
le_scan: Optional[tuple[int, int]],
|
||||
le_advertise: Optional[int],
|
||||
le_scan: tuple[int, int] | None,
|
||||
le_advertise: int | None,
|
||||
classic_page_scan: bool,
|
||||
classic_inquiry_scan: bool,
|
||||
) -> None:
|
||||
@@ -1300,7 +1299,7 @@ class IsoClient(StreamedPacketIO):
|
||||
super().__init__()
|
||||
self.device = device
|
||||
self.ready = asyncio.Event()
|
||||
self.cis_link: Optional[CisLink] = None
|
||||
self.cis_link: CisLink | None = None
|
||||
|
||||
async def on_connection(
|
||||
self, connection: Connection, cis_link: CisLink, sender: bool
|
||||
@@ -1341,7 +1340,7 @@ class IsoServer(StreamedPacketIO):
|
||||
):
|
||||
super().__init__()
|
||||
self.device = device
|
||||
self.cis_link: Optional[CisLink] = None
|
||||
self.cis_link: CisLink | None = None
|
||||
self.ready = asyncio.Event()
|
||||
|
||||
logging.info(
|
||||
|
||||
@@ -24,7 +24,6 @@ import logging
|
||||
import os
|
||||
import re
|
||||
from collections import OrderedDict
|
||||
from typing import Optional, Union
|
||||
|
||||
import click
|
||||
import humanize
|
||||
@@ -126,8 +125,8 @@ def parse_phys(phys):
|
||||
# Console App
|
||||
# -----------------------------------------------------------------------------
|
||||
class ConsoleApp:
|
||||
connected_peer: Optional[Peer]
|
||||
connection_phy: Optional[ConnectionPHY]
|
||||
connected_peer: Peer | None
|
||||
connection_phy: ConnectionPHY | None
|
||||
|
||||
def __init__(self):
|
||||
self.known_addresses = set()
|
||||
@@ -520,7 +519,7 @@ class ConsoleApp:
|
||||
|
||||
self.show_attributes(attributes)
|
||||
|
||||
def find_remote_characteristic(self, param) -> Optional[CharacteristicProxy]:
|
||||
def find_remote_characteristic(self, param) -> CharacteristicProxy | None:
|
||||
if not self.connected_peer:
|
||||
return None
|
||||
parts = param.split('.')
|
||||
@@ -542,9 +541,7 @@ class ConsoleApp:
|
||||
|
||||
return None
|
||||
|
||||
def find_local_attribute(
|
||||
self, param
|
||||
) -> Optional[Union[Characteristic, Descriptor]]:
|
||||
def find_local_attribute(self, param) -> Characteristic | Descriptor | None:
|
||||
parts = param.split('.')
|
||||
if len(parts) == 3:
|
||||
service_uuid = UUID(parts[0])
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
# -----------------------------------------------------------------------------
|
||||
import asyncio
|
||||
import time
|
||||
from typing import Optional
|
||||
|
||||
import click
|
||||
|
||||
@@ -41,7 +40,7 @@ class Loopback:
|
||||
self.transport = transport
|
||||
self.packet_size = packet_size
|
||||
self.packet_count = packet_count
|
||||
self.connection_handle: Optional[int] = None
|
||||
self.connection_handle: int | None = None
|
||||
self.connection_event = asyncio.Event()
|
||||
self.done = asyncio.Event()
|
||||
self.expected_cid = 0
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
# Imports
|
||||
# -----------------------------------------------------------------------------
|
||||
import asyncio
|
||||
from typing import Callable, Iterable, Optional
|
||||
from collections.abc import Callable, Iterable
|
||||
|
||||
import click
|
||||
|
||||
@@ -174,7 +174,7 @@ async def show_vcs(vcs: VolumeControlServiceProxy) -> None:
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
async def show_device_info(peer, done: Optional[asyncio.Future]) -> None:
|
||||
async def show_device_info(peer, done: asyncio.Future | None) -> None:
|
||||
try:
|
||||
# Discover all services
|
||||
print(color('### Discovering Services and Characteristics', 'magenta'))
|
||||
|
||||
@@ -44,7 +44,7 @@ def retrieve_config(config: str) -> dict[str, Any]:
|
||||
if not config:
|
||||
return {}
|
||||
|
||||
with open(config, 'r') as f:
|
||||
with open(config) as f:
|
||||
return json.load(f)
|
||||
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
from typing import Optional, Union
|
||||
|
||||
import click
|
||||
|
||||
@@ -190,7 +189,7 @@ class Player:
|
||||
def __init__(
|
||||
self,
|
||||
transport: str,
|
||||
device_config: Optional[str],
|
||||
device_config: str | None,
|
||||
authenticate: bool,
|
||||
encrypt: bool,
|
||||
) -> None:
|
||||
@@ -198,8 +197,8 @@ class Player:
|
||||
self.device_config = device_config
|
||||
self.authenticate = authenticate
|
||||
self.encrypt = encrypt
|
||||
self.avrcp_protocol: Optional[AvrcpProtocol] = None
|
||||
self.done: Optional[asyncio.Event]
|
||||
self.avrcp_protocol: AvrcpProtocol | None = None
|
||||
self.done: asyncio.Event | None
|
||||
|
||||
async def run(self, workload) -> None:
|
||||
self.done = asyncio.Event()
|
||||
@@ -314,7 +313,7 @@ class Player:
|
||||
codec_type: int,
|
||||
vendor_id: int,
|
||||
codec_id: int,
|
||||
packet_source: Union[SbcPacketSource, AacPacketSource, OpusPacketSource],
|
||||
packet_source: SbcPacketSource | AacPacketSource | OpusPacketSource,
|
||||
codec_capabilities: MediaCodecCapabilities,
|
||||
):
|
||||
# Discover all endpoints on the remote device
|
||||
@@ -419,7 +418,7 @@ class Player:
|
||||
async def play(
|
||||
self,
|
||||
device: Device,
|
||||
address: Optional[str],
|
||||
address: str | None,
|
||||
audio_format: str,
|
||||
audio_file: str,
|
||||
) -> None:
|
||||
@@ -448,7 +447,7 @@ class Player:
|
||||
return input_file.read(byte_count)
|
||||
|
||||
# Obtain the codec capabilities from the stream
|
||||
packet_source: Union[SbcPacketSource, AacPacketSource, OpusPacketSource]
|
||||
packet_source: SbcPacketSource | AacPacketSource | OpusPacketSource
|
||||
vendor_id = 0
|
||||
codec_id = 0
|
||||
if audio_format == "sbc":
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
# -----------------------------------------------------------------------------
|
||||
import asyncio
|
||||
import time
|
||||
from typing import Optional
|
||||
|
||||
import click
|
||||
|
||||
@@ -82,14 +81,14 @@ class ServerBridge:
|
||||
def __init__(
|
||||
self, channel: int, uuid: str, trace: bool, tcp_host: str, tcp_port: int
|
||||
) -> None:
|
||||
self.device: Optional[Device] = None
|
||||
self.device: Device | None = None
|
||||
self.channel = channel
|
||||
self.uuid = uuid
|
||||
self.tcp_host = tcp_host
|
||||
self.tcp_port = tcp_port
|
||||
self.rfcomm_channel: Optional[rfcomm.DLC] = None
|
||||
self.tcp_tracer: Optional[Tracer]
|
||||
self.rfcomm_tracer: Optional[Tracer]
|
||||
self.rfcomm_channel: rfcomm.DLC | None = None
|
||||
self.tcp_tracer: Tracer | None
|
||||
self.rfcomm_tracer: Tracer | None
|
||||
|
||||
if trace:
|
||||
self.tcp_tracer = Tracer(color("RFCOMM->TCP", "cyan"))
|
||||
@@ -242,14 +241,14 @@ class ClientBridge:
|
||||
self.tcp_port = tcp_port
|
||||
self.authenticate = authenticate
|
||||
self.encrypt = encrypt
|
||||
self.device: Optional[Device] = None
|
||||
self.connection: Optional[Connection] = None
|
||||
self.rfcomm_client: Optional[rfcomm.Client]
|
||||
self.rfcomm_mux: Optional[rfcomm.Multiplexer]
|
||||
self.device: Device | None = None
|
||||
self.connection: Connection | None = None
|
||||
self.rfcomm_client: rfcomm.Client | None
|
||||
self.rfcomm_mux: rfcomm.Multiplexer | None
|
||||
self.tcp_connected: bool = False
|
||||
|
||||
self.tcp_tracer: Optional[Tracer]
|
||||
self.rfcomm_tracer: Optional[Tracer]
|
||||
self.tcp_tracer: Tracer | None
|
||||
self.rfcomm_tracer: Tracer | None
|
||||
|
||||
if trace:
|
||||
self.tcp_tracer = Tracer(color("RFCOMM->TCP", "cyan"))
|
||||
|
||||
@@ -26,7 +26,6 @@ import pathlib
|
||||
import subprocess
|
||||
import weakref
|
||||
from importlib import resources
|
||||
from typing import Optional
|
||||
|
||||
import aiohttp
|
||||
import click
|
||||
@@ -156,7 +155,7 @@ class QueuedOutput(Output):
|
||||
|
||||
packets: asyncio.Queue
|
||||
extractor: AudioExtractor
|
||||
packet_pump_task: Optional[asyncio.Task]
|
||||
packet_pump_task: asyncio.Task | None
|
||||
started: bool
|
||||
|
||||
def __init__(self, extractor):
|
||||
@@ -230,8 +229,8 @@ class WebSocketOutput(QueuedOutput):
|
||||
class FfplayOutput(QueuedOutput):
|
||||
MAX_QUEUE_SIZE = 32768
|
||||
|
||||
subprocess: Optional[asyncio.subprocess.Process]
|
||||
ffplay_task: Optional[asyncio.Task]
|
||||
subprocess: asyncio.subprocess.Process | None
|
||||
ffplay_task: asyncio.Task | None
|
||||
|
||||
def __init__(self, codec: str) -> None:
|
||||
super().__init__(AudioExtractor.create(codec))
|
||||
|
||||
Reference in New Issue
Block a user