Skip to content

Commit

Permalink
Fix typos
Browse files Browse the repository at this point in the history
  • Loading branch information
zxzxwu committed Sep 7, 2023
1 parent 9303f4f commit bca674b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 16 deletions.
4 changes: 2 additions & 2 deletions apps/speaker/speaker.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -65,7 +65,7 @@ th, td {
}

.properties td:nth-child(even) {
background-color: #D6EEEE;
background-color: #d6eeee;
font-family: monospace;
}

Expand Down
2 changes: 1 addition & 1 deletion apps/speaker/speaker.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
22 changes: 15 additions & 7 deletions bumble/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -90,12 +96,14 @@ def __str__(self):
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}'

return f'{type(self).__name__}({namespace}{name})'
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}{error_text})'


class ProtocolError(BaseError):
Expand Down
25 changes: 19 additions & 6 deletions bumble/hfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import dataclasses
import enum
import traceback
from typing import Dict, List, Union, Set
from typing import Dict, List, Union, Set, TYPE_CHECKING

from . import at
from . import rfcomm
Expand Down Expand Up @@ -48,6 +48,15 @@
# -----------------------------------------------------------------------------
logger = logging.getLogger(__name__)

# -----------------------------------------------------------------------------
# Error
# -----------------------------------------------------------------------------


class HfpProtocolError(ProtocolError):
def __init__(self, error_name: str = '', details: str = ''):
super().__init__(None, 'hfp', error_name, details)


# -----------------------------------------------------------------------------
# Normative protocol definitions
Expand Down Expand Up @@ -302,8 +311,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):
Expand Down Expand Up @@ -368,7 +381,7 @@ def _read_at(self, data: bytes):
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).
Expand All @@ -390,15 +403,15 @@ async def execute_command(
)
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
if response_type == AtResponseType.SINGLE:
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.
Expand Down

0 comments on commit bca674b

Please sign in to comment.