Skip to content

Commit

Permalink
Merge pull request adafruit#17 from dhalbert/set_adapter
Browse files Browse the repository at this point in the history
add set_adapter(); fix new pylint complaints
  • Loading branch information
tannewt authored Sep 3, 2020
2 parents 94e25c9 + 4fb0102 commit 2660cc9
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 8 deletions.
10 changes: 10 additions & 0 deletions _bleio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

# pylint: disable=wrong-import-position

from typing import Optional

# These are in dependency order to avoid circular import issues.

from _bleio.exceptions import * # pylint: disable=redefined-builtin
Expand All @@ -46,5 +48,13 @@
from _bleio.characteristic_buffer import *
from _bleio.packet_buffer import *


def set_adapter(new_adapter: Optional[Adapter]) -> None:
"""Set the adapter to use for BLE, such as when using an HCI adapter.
Raises `NotImplementedError` when the adapter is a singleton and cannot be set.
"""
raise NotImplementedError("Not settable")


__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_Blinka_bleio.git"
4 changes: 2 additions & 2 deletions _bleio/adapter_.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

Buf = Union[bytes, bytearray, memoryview]

# Singleton _bleio.adapter is defined at the ned of this file.
# Singleton _bleio.adapter is defined at the end of this file.
adapter = None # pylint: disable=invalid-name


Expand Down Expand Up @@ -345,7 +345,7 @@ async def _connect_async(self, address: Address, *, timeout: float) -> None:
# This does not seem to connect reliably.
# await asyncio.wait_for(client.connect(), timeout)
except asyncio.TimeoutError:
raise BluetoothError("Failed to connect: timeout")
raise BluetoothError("Failed to connect: timeout") from asyncio.TimeoutError

connection = Connection._from_bleak(address, client)
self._connections.append(connection)
Expand Down
2 changes: 1 addition & 1 deletion _bleio/characteristic.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(
"""There is no regular constructor for a Characteristic. A
new local Characteristic can be created and attached to a
Service by calling `add_to_service()`. Remote Characteristic
objects are created by `Connection.discover_remote_services()`
objects are created by `_bleio.Connection.discover_remote_services`
as part of remote Services."""
self._uuid = uuid
self._properties = properties
Expand Down
4 changes: 2 additions & 2 deletions _bleio/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ class Connection:

def __init__(self, address: _bleio.address.Address):
"""Connections should not be created directly.
Instead, to initiate a connection use `Adapter.connect`.
Instead, to initiate a connection use `_bleio.Adapter.connect`.
Connections may also be made when another device initiates a connection. To use a Connection
created by a peer, read the `Adapter.connections` property.
created by a peer, read the `_bleio.Adapter.connections` property.
:param _bleio.address.Address address: _bleio.address.Address of device to connect to
"""
Expand Down
2 changes: 1 addition & 1 deletion _bleio/descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __init__(

"""There is no regular constructor for a Descriptor. A new local Descriptor can be created
and attached to a Characteristic by calling `add_to_characteristic()`.
Remote Descriptor objects are created by `Connection.discover_remote_services()`
Remote Descriptor objects are created by `_bleio.Connection.discover_remote_services`
as part of remote Characteristics in the remote Services that are discovered.
"""
self._uuid = uuid
Expand Down
2 changes: 1 addition & 1 deletion _bleio/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(
):
"""Create a new Service identified by the specified UUID. It can be accessed by all
connections. This is known as a Service server. Client Service objects are created via
`Connection.discover_remote_services`.
`_bleio.Connection.discover_remote_services`.
To mark the Service as secondary, pass `True` as :py:data:`secondary`.
Expand Down
4 changes: 3 additions & 1 deletion _bleio/uuid_.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ def __init__(self, uuid: Union[int, Buf, str]):
try:
uuid = memoryview(uuid)
except TypeError:
raise ValueError("UUID value is not str, int or byte buffer")
raise ValueError(
"UUID value is not str, int or byte buffer"
) from TypeError
if len(uuid) != 16:
raise ValueError("Byte buffer must be 16 bytes")
self._size = 128
Expand Down
2 changes: 2 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# system where bleak isn't supported.
autodoc_mock_imports = ["bleak"]

# Show the docstring from both the class and its __init__() method
autoclass_content = "both"

intersphinx_mapping = {
"python": ("https://docs.python.org/3.4", None),
Expand Down

0 comments on commit 2660cc9

Please sign in to comment.