Fix typos

This commit is contained in:
Josh Wu
2023-09-07 15:47:28 +08:00
parent cf7f2e8f44
commit 41fe63df06
4 changed files with 36 additions and 15 deletions

View File

@@ -56,7 +56,7 @@ body, h1, h2, h3, h4, h5, h6 {
border-radius: 4px;
padding: 4px;
margin: 6px;
margin-left: 0px;
margin-left: 0;
}
th, td {
@@ -65,7 +65,7 @@ th, td {
}
.properties td:nth-child(even) {
background-color: #D6EEEE;
background-color: #d6eeee;
font-family: monospace;
}

View File

@@ -2,7 +2,7 @@
<html>
<head>
<title>Bumble Speaker</title>
<script type="text/javascript" src="speaker.js"></script>
<script src="speaker.js"></script>
<link rel="stylesheet" href="speaker.css">
</head>
<body>

View File

@@ -78,7 +78,13 @@ def get_dict_key_by_value(dictionary, value):
class BaseError(Exception):
"""Base class for errors with an error code, error name and namespace"""
def __init__(self, error_code, error_namespace='', error_name='', details=''):
def __init__(
self,
error_code: int | None,
error_namespace: str = '',
error_name: str = '',
details: str = '',
):
super().__init__()
self.error_code = error_code
self.error_namespace = error_namespace
@@ -90,12 +96,14 @@ class BaseError(Exception):
namespace = f'{self.error_namespace}/'
else:
namespace = ''
if self.error_name:
name = f'{self.error_name} [0x{self.error_code:X}]'
else:
name = f'0x{self.error_code:X}'
error_text = {
(True, True): f'{self.error_name} [0x{self.error_code:X}]',
(True, False): self.error_name,
(False, True): f'0x{self.error_code:X}',
(False, False): '',
}[(self.error_name != '', self.error_code is not None)]
return f'{type(self).__name__}({namespace}{name})'
return f'{type(self).__name__}({namespace}{error_text})'
class ProtocolError(BaseError):

View File

@@ -22,7 +22,7 @@ import dataclasses
import enum
import traceback
import warnings
from typing import Dict, List, Union, Set
from typing import Dict, List, Union, Set, TYPE_CHECKING
from . import at
from . import rfcomm
@@ -51,6 +51,15 @@ from bumble.sdp import (
# -----------------------------------------------------------------------------
logger = logging.getLogger(__name__)
# -----------------------------------------------------------------------------
# Error
# -----------------------------------------------------------------------------
class HfpProtocolError(ProtocolError):
def __init__(self, error_name: str = '', details: str = ''):
super().__init__(None, 'hfp', error_name, details)
# -----------------------------------------------------------------------------
# Protocol Support
@@ -361,8 +370,12 @@ class HfProtocol:
dlc: rfcomm.DLC
command_lock: asyncio.Lock
response_queue: asyncio.Queue
unsolicited_queue: asyncio.Queue
if TYPE_CHECKING:
response_queue: asyncio.Queue[AtResponse]
unsolicited_queue: asyncio.Queue[AtResponse]
else:
response_queue: asyncio.Queue
unsolicited_queue: asyncio.Queue
read_buffer: bytearray
def __init__(self, dlc: rfcomm.DLC, configuration: Configuration):
@@ -427,7 +440,7 @@ class HfProtocol:
else:
logger.warning(f"dropping unexpected response with code '{response.code}'")
# Send an AT command and wait for the peer resposne.
# Send an AT command and wait for the peer response.
# Wait for the AT responses sent by the peer, to the status code.
# Raises asyncio.TimeoutError if the status is not received
# after a timeout (default 1 second).
@@ -449,7 +462,7 @@ class HfProtocol:
)
if result.code == 'OK':
if response_type == AtResponseType.SINGLE and len(responses) != 1:
raise ProtocolError("NO ANSWER")
raise HfpProtocolError("NO ANSWER")
if response_type == AtResponseType.MULTIPLE:
return responses
@@ -457,7 +470,7 @@ class HfProtocol:
return responses[0]
return None
if result.code in STATUS_CODES:
raise ProtocolError(result.code)
raise HfpProtocolError(result.code)
responses.append(result)
# 4.2.1 Service Level Connection Initialization.