Typing transport

This commit is contained in:
Josh Wu
2023-09-07 16:48:55 +08:00
parent 9303f4fc5b
commit b312170d5f
19 changed files with 188 additions and 99 deletions

View File

@@ -17,6 +17,7 @@
# -----------------------------------------------------------------------------
import logging
from .common import Transport
from .file import open_file_transport
# -----------------------------------------------------------------------------
@@ -26,7 +27,7 @@ logger = logging.getLogger(__name__)
# -----------------------------------------------------------------------------
async def open_vhci_transport(spec):
async def open_vhci_transport(spec: str | None) -> Transport:
'''
Open a VHCI transport (only available on some platforms).
The parameter string is either empty (to use the default VHCI device
@@ -42,15 +43,15 @@ async def open_vhci_transport(spec):
# Override the source's `data_received` method so that we can
# filter out the vendor packet that is received just after the
# initial open
def vhci_data_received(data):
def vhci_data_received(data: bytes) -> None:
if len(data) > 0 and data[0] == HCI_VENDOR_PKT:
if len(data) == 4:
hci_index = data[2] << 8 | data[3]
logger.info(f'HCI index {hci_index}')
else:
transport.source.parser.feed_data(data)
transport.source.parser.feed_data(data) # type: ignore
transport.source.data_received = vhci_data_received
transport.source.data_received = vhci_data_received # type: ignore
# Write the initial config
transport.sink.on_packet(bytes([HCI_VENDOR_PKT, HCI_BREDR]))