Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typos #270

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -22,7 +22,7 @@
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
Expand Down Expand Up @@ -51,6 +51,15 @@
# -----------------------------------------------------------------------------
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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -427,7 +440,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 @@ -449,15 +462,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